HOW TO IMPLEMENTS OF INHERITANCE IN JAVA?

Kamlakar Singh

Total Post:28

Points:196
Posted by  Kamlakar Singh
Java  OOPS 
 859  View(s)
Ratings:
Rate this:
example of inheritance in java
  1. Kamlakar Singh

    Post:194

    Points:1396
    Re: How to implements of inheritance in java?

    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();

        }

    }

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!