Inheritance and Polymorphism Flashcards

1
Q

What is inheritance in Java?

A

Inheritance allows a subclass to inherit attributes and behaviors from a superclass, promoting code reuse.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are three principles of Object-Oriented Programming (OOP)?

A

Abstraction, Encapsulation, and Inheritance (which includes Polymorphism)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What does polymorphism enable?

A

Subclass objects to be used wherever superclass objects are expected.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is a superclass in Java?

A

A class that other classes (subclasses) inherit from.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What are some common methods in the Geometric0bject class?

A

getColor(), setColor(), isFilied(), getDateCreated(), and toString().

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Name a method unique to the Circle subclass.

A

getDiamter()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Is a subclass a subset of its superclass?

A

No, it may include additional attributes and methods.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is the superclass of all Java classes?

A

java.lang.0bject.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is the super keyword used in for in Java?

A

You call a superclass constructor or a superclass method.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

who can access protected methods?

A

Subclasses and classes on the same package

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Are contructors inherited in Java?

A

No, they must be explicitly invoked using super() in a subclass constructor method.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What happens if super() is not used in subclass constructor?

A

The no-arg constructor of the superclass is automatically called.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

what happens if you call a superclass constructor without using super?

A

It causes a syntax error

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Where must super() appear in a constructor

A

As the first statement.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What does the compiler add to a constructer if no call to a superclass constructor is made?

A

super();

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is constructor chaining?

A

When subclass constructors call superclass constructors all the way up the inheritance chain.

17
Q

What happens when you create new Faculty() object?

A

All parent class constructors are invoked in order.

18
Q

How do you do a Trace Execution?

A

public class Faculty extends Employee { public static viod main (string [] args { new Faculty (); }