Multiple Inheritence in Java /How to inherit a class from another in Java| Programmer Hub
Multiple Inheritence in Java I nheritance 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) { ...
Comments
Post a Comment