









Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!










๏ private keyword ๏ Used for most instance variables ๏ private variables and methods are accessible only to methods of the class in which they are declared ๏ Declaring instance variables private is known as data hiding ๏ public keyword ๏ Exposes variables or methods outside the Class. ๏ Declaring public methods is know as defining the classโ public interface. ๏ Protected keyword ๏ Provides limited access ๏ Provides access to sub classes but not to the classes outside a package
๏ Good class design puts all common features as high in the hierarchy as reasonable ๏ inheritance is transitive ๏ An instance of class Parrot is also an instance of Bird, an instance of Animal, โฆ, and an instance of class Object
๏ The inclusion of members of a base class in a derived class so that they are accessible in that derived class is called class inheritance. ๏ An inherited member of a base class is one that is accessible within the derived class. ๏ If a base class member is not accessible in a derived class, then it is not an inherited member of the derived class.
๏ Variables of same name both in base class and derived class ๏ Use of keyword super
// A simple example of inheritance. // Create a superclass. class A { int i, j; void showij() { System.out.println("i and j: " + i + " " + j); } } // Create a subclass by extending class A. class B extends A { int k; void showk() { System.out.println("k: " + k); } void sum() { System.out.println("i+j+k: " + (i+j+k)); } }
class SimpleInheritance { public static void main(String args[]) { A superOb = new A(); B subOb = new B(); //The superclass may be used by itself. superOb.i = 10; superOb.j = 20; System.out.println("Contents of superOb: "); superOb.showij(); System.out.println();