How to implements of inheritance in java?

Total Post:28

Points:196
Java  OOPS 
 1140  View(s)
Ratings:
Rate this:
example of inheritance in java
  1. 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();
        }
    }

      Modified On Apr-05-2018 11:28:56 PM

Answer

NEWSLETTER

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