Construction chaining or constructor hierarchy
Previous | Home | Next |
Following program for display the Construction chaining or constructor hierarchy.
/* * save as a AnimalProperty.java * Program display the Construction chaining or constructor hierarchy. * Three level of class extend each other by extend keyword */ package r4r.co.in; public class AnimalProperty { public static void main(String[] args) { Cat c = new Cat(); //Create an object } } class Cat extends Dog { /* * Define a Construction. * Construction is the same name as a class name(property of Construction) */ public Cat() { System.out.println("Cat also hates Dogs,but faster than dog "); } } class Dog extends Animal { public Dog() { System.out.println("Dog is Barking on Cat, even hates cats "); } } class Animal { public Animal() { System.out.println("Animal Property: Dog is bigger than Cat "); } }
Animal Property: Dog is bigger than Cat
Dog is Barking on Cat, even hates cats
Cat also hates Dogs,but faster than dog
Previous | Home | Next |