Java Unit 9 Flashcards
19 Questions
100 Views

Java Unit 9 Flashcards

Created by
@CorrectSaxhorn

Questions and Answers

What is class hierarchy?

  • A class that does not inherit from others.
  • A class defined without any hierarchy.
  • A structure where classes are isolated.
  • A class displays classes in a hierarchy. (correct)
  • What is a superclass?

    The parent class of a subclass.

    What is a subclass?

    Derived from a superclass.

    When a class is extended, a subclass is created that may add more variables, methods, etc. than the original class had. This is done using the keyword __________.

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

    What does it mean to inherit in the context of classes?

    <p>When a class inherits from another class, it automatically contains the variables and methods defined in the superclass.</p> Signup and view all the answers

    What does is-a relationship mean?

    <p>Used when describing the relationship between a subclass and a superclass.</p> Signup and view all the answers

    What is inheritance?

    <p>The process by which a class automatically contains the variables and methods defined in its superclass.</p> Signup and view all the answers

    What do public methods allow?

    <p>They can be seen and used by other classes.</p> Signup and view all the answers

    What code should replace in the RightTriangle class?

    <p>super(s1, s2, Math.sqrt(Math.pow(s1, 2) + Math.pow(s2, 2)))</p> Signup and view all the answers

    A class _____ from all of its _______ all public methods and instance variables.

    <p>inherits, superclasses</p> Signup and view all the answers

    What is a direct subclass?

    <p>A subclass that has no classes in between itself and its superclass.</p> Signup and view all the answers

    What does it mean for a class to be derived?

    <p>A class that extends another class.</p> Signup and view all the answers

    What is polymorphism?

    <p>The ability of being able to assign a different usage to a method.</p> Signup and view all the answers

    What is down-casting in object-oriented programming?

    <p>Using subclass methods for objects originally casted as superclasses.</p> Signup and view all the answers

    What does overriding a method entail?

    <p>A method in a subclass provides a different implementation than the original method in the superclass.</p> Signup and view all the answers

    How to override a method in Java?

    <p>Method #1 is defined in a superclass, and methods #1 and #2 have matching signatures.</p> Signup and view all the answers

    What is a static method?

    <p>A synonym for class method.</p> Signup and view all the answers

    What is a non-static method?

    <p>A synonym for object method.</p> Signup and view all the answers

    What happens if the main method were a non-static instance method?

    <p>Nothing can happen before the main method executes.</p> Signup and view all the answers

    Study Notes

    Class Hierarchy

    • A class hierarchy visually organizes classes in a structured format, illustrating subclasses beneath their associated superclasses.
    • Demonstrates relationships between classes, showing specialization.

    Superclass and Subclass

    • A superclass is the parent class from which a subclass is derived; subclasses can extend their superclasses with additional features.
    • Subclasses inherit properties from their superclass, potentially with intermediary classes in the hierarchy.

    Extend Keyword

    • The extends keyword is used in Java to create a subclass from a superclass, enabling incorporation of new variables and methods.
    • Example: public class SalesAssistant extends Employee;.

    Inheritance

    • Inheritance allows a class to automatically inherit variables and methods from its superclass, promoting code reuse.
    • A subclass can access public methods and variables defined in its superclass.

    Is-a Relationship

    • The "is-a" relationship defines that a subclass is a type of its superclass, signifying a hierarchical connection.

    Public Methods

    • Public methods and variables within a class are accessible from other classes, enhancing modularity.

    Direct Subclass

    • A direct subclass has no intermediate classes between it and its superclass, directly inheriting properties.

    Derived Classes

    • A derived class extends another class, making it a subclass, facilitating specialization of behavior.

    Polymorphism

    • Polymorphism enables methods to handle objects of different subclasses interchangeably, enhancing flexibility in code.
    • Ensures derived class methods are usable as long as they share common interfaces.

    Down-Casting

    • Down-casting allows a superclass reference to call subclass-specific methods and properties, enhancing functionality.

    Method Overriding

    • Overriding occurs when a subclass provides a new implementation of a method already defined in its superclass.
    • Requires matching method signatures between the subclass and superclass.

    Static Methods

    • Static methods belong to the class itself, not to any instance, used for operations that do not require object-level data.
    • Example: All methods in the Math class are static.

    Instance and Non-static Methods

    • Instance or non-static methods operate on object instances; they can be overridden and are bound to object states.

    Main Method Consideration

    • The main method must be static; if it were non-static, program execution would stall as no objects exist to invoke it.
    • Emphasizes the necessity of static context for the entry point of Java applications.

    Method Calling Summary

    • Both class methods and instance methods of one class are capable of invoking any public class methods in Java, facilitating interaction between classes.

    Studying That Suits You

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

    Quiz Team

    Description

    Test your knowledge with these Java Unit 9 flashcards. Covering key concepts like class hierarchy, superclass, and subclass, this quiz will strengthen your understanding of object-oriented programming in Java. Perfect for students aiming to master these fundamental ideas.

    More Quizzes Like This

    Use Quizgecko on...
    Browser
    Browser