Scientific Programming Chapter 9 Flashcards
26 Questions
100 Views

Scientific Programming Chapter 9 Flashcards

Created by
@MesmerizingBongos

Questions and Answers

What does the keyword 'extends' indicate?

  • A class is declared final
  • A superclass has multiple subclasses
  • A class implements an interface
  • A subclass will inherit from a superclass (correct)
  • What is the Object class in Java?

  • The superclass of all Java classes (correct)
  • A class with no methods
  • The first class that is declared in a program
  • A class that cannot be inherited
  • What is class hierarchy?

    A set of classes related by inheritance.

    What does 'protected' mean in terms of access modifiers?

    <p>Protected members can be accessed in the class in which they are defined and in all subclasses of that class.</p> Signup and view all the answers

    What is inheritance in object-oriented programming?

    <p>An is-a relationship.</p> Signup and view all the answers

    What does the 'super' keyword do?

    <p>It refers to an object's superclass members.</p> Signup and view all the answers

    Define direct superclass.

    <p>A subclass's immediate superclass.</p> Signup and view all the answers

    What is meant by 'brittle software'?

    <p>A small change in the superclass can break subclass implementations.</p> Signup and view all the answers

    What does it mean to override a method?

    <p>To define a subclass method with the same signature as a superclass method.</p> Signup and view all the answers

    What is a clone method?

    <p>A protected method that takes no arguments and returns a copy of the object on which it is called.</p> Signup and view all the answers

    Define indirect superclass.

    <p>A class that a subclass does not directly extend but still has an is-a relationship with the class.</p> Signup and view all the answers

    A subclass can explicitly invoke a constructor of its superclass by using the superclass constructor call syntax-keyword ______ followed by a set of parentheses containing the superclass constructor's arguments.

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

    Every object of a _____ is also an object of that class's _____. However, a _____ object is not an object of any of its _____.

    <p>subclass, superclass, superclass, subclasses</p> Signup and view all the answers

    In a(n) _____ relationship, an object has a reference to an object of another class as a member.

    <p>has-a</p> Signup and view all the answers

    In a(n) _____ relationship, an object of a subclass type may also be treated as an object of the superclass type.

    <p>is-a</p> Signup and view all the answers

    What are standardized reusable components?

    <p>Components that new software is likely to be constructed from.</p> Signup and view all the answers

    What does private mean in terms of member access?

    <p>A subclass cannot directly access private members of its superclass.</p> Signup and view all the answers

    What is the direct superclass of a subclass?

    <p>The superclass from which the subclass inherits.</p> Signup and view all the answers

    With _____ inheritance, a class is derived from one superclass. Java does not support _____ inheritance.

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

    A subclass inherits the members of its superclass that are declared with the access specifiers _____ and _____

    <p>public, protected</p> Signup and view all the answers

    Which class normally overrides the toString method?

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

    How does inheritance promote software reusability?

    <p>Inheritance enables programmers to create new classes from existing classes by absorbing their attributes and behaviors.</p> Signup and view all the answers

    Explain protected member access.

    <p>Protected members are accessible to the defining class, all subclasses, and other classes in the same package.</p> Signup and view all the answers

    Explain the difference between composition and inheritance.

    <p>With inheritance, a class inherits attributes and behaviors from another class. With composition, a class is composed of objects of existing classes.</p> Signup and view all the answers

    Explain the initialization process for an object of class BasePlusCommissionEmployee.

    <p>The BasePlusCommissionEmployee constructor is called, which calls CommissionEmployee's constructor, which then calls Object's constructor.</p> Signup and view all the answers

    How to invoke a superclass method from a subclass method?

    <p>Use the keyword super to invoke the superclass method if the subclass method overrides it; otherwise, use the name of the superclass method.</p> Signup and view all the answers

    Study Notes

    Java Inheritance Concepts

    • Inheritance allows a subclass to inherit properties and methods from a superclass, creating a hierarchical relationship.
    • The Object class serves as the ultimate superclass for all Java classes.
    • Class relationships established through inheritance are termed class hierarchy.

    Access Modifiers

    • Protected members can be accessed within the defining class and all its subclasses, as well as other classes in the same package.
    • Private members remain inaccessible to subclasses, ensuring encapsulation.
    • Members declared with public and protected access specifiers are inherited by subclasses.

    Keywords in Inheritance

    • The extends keyword indicates that a subclass inherits from a particular superclass.
    • The super keyword is used to refer to superclass members and to call a superclass constructor.
    • When a subclass invokes a constructor of its superclass, it does so with the super keyword followed by the appropriate parameters.

    Types of Relationships

    • Is-a relationship indicates that a subclass is a specialized type of a superclass.
    • Has-a relationship signifies that an object includes a reference to another object as a member.
    • Inheritance leads to brittle software, where minor changes in superclasses can disrupt subclass functionality.

    Method Overriding and Cloning

    • Method override occurs when a subclass defines a method with the same signature as a method in its superclass.
    • The clone method is a protected method that creates a copy of the object it is called on.

    Composition vs. Inheritance

    • Inheritance grants a new class attributes and behaviors from an existing one, allowing for dual treatment as its type and superclass types.
    • Composition involves creating a new class from existing classes’ instances, where the new class typically cannot be treated as an instance of the component classes.

    Object Initialization

    • When creating an object of a derived class, constructors from the superclass are invoked in sequence, starting from the highest ancestor.
    • In the BasePlusCommissionEmployee example, constructors are called in a chain from Object to CommissionEmployee, finally reaching BasePlusCommissionEmployee, which initializes additional attributes.

    Accessing Superclass Methods

    • To invoke a superclass method from an overriding subclass method, use the super keyword.
    • If the subclass method does not override the superclass one, simply call the superclass method by its name with the necessary arguments.

    Software Design Principles

    • Standardized reusable components are a future trend in software construction, paralleling manufacturing practices in industries like automotive.

    Studying That Suits You

    Use AI to generate personalized quizzes and flashcards to suit your learning preferences.

    Quiz Team

    Description

    Test your understanding of key concepts from Chapter 9 of Scientific Programming. This quiz covers essential terminology relating to class inheritance, object classes, and access modifiers in Java. Flashcards are a great way to reinforce your learning and prepare for exams.

    More Quizzes Like This

    Use Quizgecko on...
    Browser
    Browser