unit 9 Flashcards

1
Q

What is inheritance in Java?

A

A mechanism where one class acquires the properties and behaviors of another class.

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

What is a superclass?

A

The parent class whose features are inherited.

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

What is a subclass?

A

The child class that inherits from the superclass.

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

How do you define a subclass?

A

public class SubclassName extends SuperclassName

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

What keyword is used to create a subclass?

A

extends

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

Can a subclass have its own fields and methods?

A

Yes

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

What is method overriding?

A

Providing a new version of a method in the subclass with the same signature.

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

What keyword is used to call a superclass constructor?

A

super

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

Where must the call to super() appear in a constructor?

A

First line of the subclass constructor.

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

What happens if no constructor is written in a subclass?

A

The compiler automatically inserts a call to super().

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

Can constructors be overridden?

A

No

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

What is polymorphism?

A

The ability for the same method call to behave differently depending on the object’s runtime type.

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

What happens when you assign a subclass object to a superclass reference?

A

The reference can call only the methods declared in the superclass (unless overridden).

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

What is dynamic method dispatch?

A

The method that gets called is determined by the object’s actual type at runtime.

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

Can a superclass reference call a subclass-only method?

A

No

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

What is an abstract class?

A

A class that cannot be instantiated and may contain abstract methods.

17
Q

What is an abstract method?

A

A method without a body that must be implemented by subclasses.

18
Q

Does Java support multiple inheritance of classes?

19
Q

What class does every Java class ultimately extend?

A

The Object class.

20
Q

What are common methods from the Object class?

A

toString()

21
Q

What is toString() used for?

A

Returning a string representation of an object.

22
Q

What is equals() used for?

A

Comparing two objects for logical equality.

23
Q

What is @Override annotation used for?

A

Indicating that a method is overriding a superclass method.

24
Q

What is upcasting?

A

Treating a subclass object as if it were a superclass object.

25
What is downcasting?
Casting a superclass reference back to a subclass type.