Home > DeveloperSection > Forums > How to implements of inheritance in java?
Kamlakar Singh
Kamlakar Singh

Total Post:28

Points:196
Posted on    October-10-2014 12:56 AM

 Java Java  OOPS 
Ratings:


 1 Reply(s)
 572  View(s)
Rate this:
example of inheritance in java


Kamlakar Singh
Kamlakar Singh

Total Post:194

Points:1396
Posted on    October-10-2014 12:57 AM

try this:

class Parent {

    Parent(int a, int b) {

        int c = a + b;

        System.out.println("Sum=" + c);

    }

    void display() {

        System.out.println("Return Statement");

    }

}

class Child extends Parent {

    Child(int a, int b) {

        int c = a - b;

        System.out.println("Difference=" + c);

    }

}

public class InheritanceExample {

    public static void main(String args[]) {

        Child c = new Child(2, 1);

        c.display();

    }

}


Don't want to miss updates? Please click the below button!

Follow MindStick