Class Inheritance Code Samples
Learn about classes, member variables, methods, inheritance, nested classes, and more.
- Creating Classes
- Inheritance
Creating Classes
- AClass.java declares an instance member variable, an instance method, a class variable, a class method, and main. For supporting information see The Java Tutorial: Classes and Inheritance.
- Alpha.java declares members with various access levels (public, private, protected). For supporting information see The Java Tutorial: Classes and Inheritance.
- AlphaTwo.java is a subclass of Alpha but in a different package. For supporting information see The Java Tutorial: Classes and Inheritance.
- DeltaOne.java has methods and variables that can be used by other classes in the same package. For supporting information see The Java Tutorial: Classes and Inheritance.
- DeltaTwo.java is not related to and is in a different package from Alpha so can access only the public members of Alpha. For supporting information see The Java Tutorial: Classes and Inheritance.
- Stack.java implements a stack (data structure) whose items are added and removed in a last-in-first-out (LIFO) fashion. For supporting information see The Java Tutorial: Classes and Inheritance.
Inheritance
- Planet.java contains one instance method and one class method. For supporting information see The Java Tutorial: Classes and Inheritance.
- Subclass.java overrides a method and hides a variable in its super class. For supporting information see The Java Tutorial: Classes and Inheritance.
- Superclass.java shows how to use super to invoke an overridden method. For supporting information see The Java Tutorial: Classes and Inheritance.