Java Abstract Classes Flashcards
5 Questions
100 Views

Java Abstract Classes Flashcards

Created by
@WellConnectedComputerArt

Questions and Answers

Which of the following statements is true concerning abstract classes in Java? (Select all that apply)

  • An abstract class can be used to instantiate an object of its own by using the new operator.
  • Constructors can be abstract.
  • All abstract methods declared in an abstract class must be defined inside the same abstract class.
  • An abstract class can be used to create an object reference (reference variable). (correct)
  • 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 ?

  • 2
  • 10
  • 1
  • 0 (correct)
  • An abstract class may be defined without any abstract method.

    <p>True</p> 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.

    <p>True</p> 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.

    Quiz Team

    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.

    More Quizzes Like This

    Java Chapter 13 Flashcards
    28 questions
    Abstract Classes and Methods Quiz
    18 questions
    Use Quizgecko on...
    Browser
    Browser