Multiple Inheritence in Java /How to inherit a class from another in Java| Programmer Hub

Multiple Inheritence in Java

Inheritance allows to reuse classes by deriving a
new class from an existing one.The existing class is called the parent class, or
super class, or base class.

The derived class is called the child class or
subclass or derived class. The child inherits characteristics of the parent(i.e the child class inherits the methods and data defined for the parent class).

Code:

package inhert;
class Animal{
    String color="Brown";
    String weight="55 kg";  
}
class Dog extends Animal{
    void display(){
        String color=super.color;
   String weight=super.weight;
        System.out.println("Color of Dog is " +color);
        System.out.println("Weight of Dog is "+weight);
    } 
}
public class Inhert {
public static void main(String[] args) {
   Dog obj=new Dog();
   obj.display();
    }
}

Output:

Color of Dog is Brown
Weight of Dog is 55 kg

how to use multiple inheritence in java

 


Comments

Popular posts from this blog

GUI in Java | How to make userdefined login page in graphical user interface in java

Search an Element in Arraylist in java | Programming Hub