Questions and Answers
What is class hierarchy?
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 __________.
Signup and view all the answers
What does it mean to inherit in the context of classes?
Signup and view all the answers
What does is-a relationship mean?
Signup and view all the answers
What is inheritance?
Signup and view all the answers
What do public methods allow?
Signup and view all the answers
What code should replace
Signup and view all the answers
A class _____ from all of its _______ all public methods and instance variables.
Signup and view all the answers
What is a direct subclass?
Signup and view all the answers
What does it mean for a class to be derived?
Signup and view all the answers
What is polymorphism?
Signup and view all the answers
What is down-casting in object-oriented programming?
Signup and view all the answers
What does overriding a method entail?
Signup and view all the answers
How to override a method in Java?
Signup and view all the answers
What is a static method?
Signup and view all the answers
What is a non-static method?
Signup and view all the answers
What happens if the main method were a non-static instance method?
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.
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.