Inheritance and Polymorphism Flashcards
What is inheritance in Java?
Inheritance allows a subclass to inherit attributes and behaviors from a superclass, promoting code reuse.
What are three principles of Object-Oriented Programming (OOP)?
Abstraction, Encapsulation, and Inheritance (which includes Polymorphism)
What does polymorphism enable?
Subclass objects to be used wherever superclass objects are expected.
What is a superclass in Java?
A class that other classes (subclasses) inherit from.
What are some common methods in the Geometric0bject class?
getColor(), setColor(), isFilied(), getDateCreated(), and toString().
Name a method unique to the Circle subclass.
getDiamter()
Is a subclass a subset of its superclass?
No, it may include additional attributes and methods.
What is the superclass of all Java classes?
java.lang.0bject.
What is the super keyword used in for in Java?
You call a superclass constructor or a superclass method.
who can access protected methods?
Subclasses and classes on the same package
Are contructors inherited in Java?
No, they must be explicitly invoked using super() in a subclass constructor method.
What happens if super() is not used in subclass constructor?
The no-arg constructor of the superclass is automatically called.
what happens if you call a superclass constructor without using super?
It causes a syntax error
Where must super() appear in a constructor
As the first statement.
What does the compiler add to a constructer if no call to a superclass constructor is made?
super();
What is constructor chaining?
When subclass constructors call superclass constructors all the way up the inheritance chain.
What happens when you create new Faculty() object?
All parent class constructors are invoked in order.
How do you do a Trace Execution?
public class Faculty extends Employee { public static viod main (string [] args { new Faculty (); }