Knowledge Walls
Java Master
Hyderabad, Andhra Pradesh, India
Extend a Class in Examples of Core Java
3534 Views
MyObjectExample
class A {
    A() {
        System.out.println("Constractor Of A");
    }

    void test() {
        System.out.println("Class A");
    }
}

class B extends A {
    B() {
        System.out.println("Constractor Of B");
    }

    void test() {
        System.out.println("Class B");
    }
}

class C extends B {
    C() {
        System.out.println("Constractor Of C");
    }

    void test() {
        System.out.println("Class C");
    }
}

class MyObjectExample {
    public static void main(String args[]) {
        System.out.println("Main Class");

        A o1 = new B();
        // B 02 = new A(); Error
        A o3 = new C();
        o1.test();
        o3.test();
        new A().test();
        new B().test();
        new C().test();
    }
}
Example
Main Class
Constractor Of A
Constractor Of B
Constractor Of A
Constractor Of B
Constractor Of C
Class B
Class C
Constractor Of A
Class A
Constractor Of A
Constractor Of B
Class B
Constractor Of A
Constractor Of B
Constractor Of C
Class C
Hints 
Java is allowed to extend more class to one class. So that java is not supporting Multiple inheritance.
One or more interfaces can implement with a Java Class.
Interfaces used to get more type of definitions from the same class definitions.
Next Topics
Next lessons of current book.
  Copyright © 2014 Knowledge walls, All rights reserved
KnowledgeWalls
keep your tutorials and learnings with KnowledgeWalls. Don't lose your learnings hereafter. Save and revise it whenever required.
Click here for more details