single inheritance program in java

Inheritance is the veri important in Object oriented language. java is fuuly object oriented language so, it will supports the inheritance
java supports many type of inheritance

The below code demostrate the Single inheritance in which Child class inherites the all the property of the parent class

class Mobile {
public void MobileMethod() {
System.out.println(“I am Mobile class and I am a parent”);
}
}

class Android extends Mobile {
public void AndroidMethod() {
System.out.println(“I am Android class and I am a Child of Mobile class”);
}
}

public class SingleInheritanceExample {

public static void main(String[] args) {
// Create the parent calss object and called the parent method
Mobile objMobile = new Mobile();
objMobile.MobileMethod();

// Create the child calss object and called the child method
Android objAnroid = new Android();
objAnroid.AndroidMethod();

// Called the parent method using child class object
objAnroid.MobileMethod();
}
}

Output
I am Mobile class and I am a parent
I am Android class and I am a Child of Mobile class
I am Mobile class and I am a parent

Post to Twitter