Questions and Answers
Which of the following statements is true concerning abstract classes in Java? (Select all that apply)
In Java, a class can implement multiple interfaces.
True
If you define an abstract class called MyClass (with 2 data fields) in Java that is inherited by a class called AnotherClass, how many AnotherClass objects are instantiated in the heap once the following statement is executed: MyClass [] mc = new AnotherClass ?
An abstract class may be defined without any abstract method.
Signup and view all the answers
In the following inheritance-chain diagram, a non-static, and non-final public method in Class_1 can be overridden in Class_3.
Signup and view all the answers
Study Notes
Abstract Classes in Java
- An abstract class cannot have abstract constructors, thus option A is incorrect.
- Abstract classes allow the creation of an object reference (option B is correct).
- It is not possible to instantiate an abstract class directly using the new operator (option C is incorrect).
- Not all abstract methods need to be defined in the same abstract class, so option D is incorrect.
Interfaces in Java
- A class can implement multiple interfaces, demonstrating Java's support for multiple inheritance through interfaces.
Object Instantiation in Inheritance
- If an abstract class MyClass is extended by AnotherClass and the statement
MyClass[] mc = new AnotherClass;
is executed, 0 AnotherClass objects are instantiated in the heap.
Abstract Class Flexibility
- An abstract class can exist without any abstract methods, allowing for flexible design even without enforcing method implementations.
Method Overriding in Inheritance
- In inheritance chains, a non-static, non-final public method in a base class can be overridden by a subclass, indicating the dynamic nature of method resolution in Java.
Studying That Suits You
Use AI to generate personalized quizzes and flashcards to suit your learning preferences.
Description
Test your knowledge on abstract classes in Java with these flashcards. Learn about constructors, object references, and method definitions specific to abstract classes. Perfect for anyone looking to solidify their understanding of this important Java concept.