Java Chapter 7 Flashcards
25 Questions
100 Views

Java Chapter 7 Flashcards

Created by
@EffortlessGyrolite7402

Questions and Answers

A base class is synonymous with a:

  • Derived class (correct)
  • Sub class
  • Parent class (correct)
  • Child class
  • A constructor for a derived class begins with an invocation of a constructor for the base class.

    True

    A derived class contains only public instance variables and public methods from the base class.

    False

    A derived class is a class defined by adding instance variables and methods to an existing class.

    <p>True</p> Signup and view all the answers

    A derived class is also called a:

    <p>Sub class</p> Signup and view all the answers

    A method or instance variable modified by protected:

    <p>Cannot be accessed by name in any other class (that is, other than classes named in A-C.)</p> Signup and view all the answers

    A super class is also called a:

    <p>Base class</p> Signup and view all the answers

    An instance variable (or method) that is private in a base class is accessible by name in the definition of a method in any other class.

    <p>False</p> Signup and view all the answers

    An object of a derived class has the type of the derived class, and it also has the type of the base class, and more generally, has the type of every one of its ________ classes.

    <p>Ancestor</p> Signup and view all the answers

    If an instance variable is not modified by public, protected, or private then it is said to have:

    <p>All of these</p> Signup and view all the answers

    If the final modifier is added to the definition of a method, this means:

    <p>The method may not be redefined in the derived class.</p> Signup and view all the answers

    In using the keyword this in place of super(), the invocation of this must be the ________ action taken by the constructor.

    <p>first</p> Signup and view all the answers

    Inheritance is the process by which a new class known as a ________ is created from another class, called the ________.

    <p>base class = inherited class derived class = base class inherited class = base class</p> Signup and view all the answers

    Inheritance promotes code:

    <p>Reuse</p> Signup and view all the answers

    Overriding is when a derived class redefines a method from the base class.

    <p>True</p> Signup and view all the answers

    Private methods of the base class are not available for use by derived classes.

    <p>True</p> Signup and view all the answers

    The Object class contains the method:

    <p>All of these</p> Signup and view all the answers

    The call to the base class constructor (super) must always be the last action taken in a constructor definition.

    <p>False</p> Signup and view all the answers

    The class ________ is an ancestor class of all Java classes.

    <p>Object</p> Signup and view all the answers

    The equals method for a class should have ________ as the type of its one parameter.

    <p>Object</p> Signup and view all the answers

    The keyword extends indicates:

    <p>Inheritance</p> Signup and view all the answers

    The special syntax for invoking a constructor of the base class is:

    <p>super()</p> Signup and view all the answers

    What does a derived class automatically inherit from the base class?

    <p>All of these</p> Signup and view all the answers

    When you define a derived class, you give only the added instance variables and the added methods as well as all the methods from the base class.

    <p>False</p> Signup and view all the answers

    You may substitute the keyword this for super() to call a constructor of...

    <p>True</p> Signup and view all the answers

    Study Notes

    Class Hierarchy and Inheritance

    • Parent class refers to a base class from which other classes can derive.
    • A derived class is synonymous with a subclass, indicating the relationship in inheritance.
    • A constructor in a derived class begins by invoking the constructor of the base class, ensuring proper initialization.

    Access Modifiers and Visibility

    • The private instance variables or methods in a base class are not accessible in any derived class.
    • Protected variables can only be accessed by derived classes and classes in the same package, limiting visibility.
    • If an instance variable is not specified as public, protected, or private, it has default access (package access).

    Final Keyword

    • If a method is marked with the final modifier, it cannot be redefined in any derived class, ensuring its integrity.
    • The invocation of this must be the first action taken by the constructor when substituting for super().

    Object Class and Methods

    • The Object class serves as the ancestor for all Java classes, providing fundamental methods such as getClass(), toString(), and equals().
    • The equals method should take an Object parameter to ensure compatibility with all Java object types.

    Inheritance Mechanism

    • Inheritance allows a new class (derived class) to be created from an existing class (base class), promoting code reuse.
    • Derived classes inherit instance variables, static variables, and public methods from their base class.
    • Overriding occurs when a derived class redefines a method from its base class.

    Inheritance Keywords

    • The extends keyword indicates inheritance in Java, specifying the relationship between base and derived classes.
    • The special keyword super() is used to call the constructor of the base class within a derived class.

    Truth Statements

    • A derived class is defined by adding instance variables and methods to an existing class.
    • Private methods from the base class cannot be accessed by the derived class, maintaining encapsulation.
    • The call to the base class constructor (super) does not need to be the last action in a constructor.

    General Concepts

    • Instantiation of a derived class results in an object that holds the type of the derived class and its base class, extending to all ancestor types.
    • Code reuse through inheritance reduces redundancy and promotes better organization of code 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 of key concepts from Java Chapter 7 with these flashcards. Explore important terms like parent class, constructors, and the relationship between derived and base classes. Perfect for reinforcing your understanding of object-oriented programming in Java!

    Use Quizgecko on...
    Browser
    Browser