JAVATECH NEWS

Java

CORE JAVA

Interview

OFF-CAMPUS

Saturday, 8 November 2014

Accessing the Super class Constructor


We need not to access the super class default Constructor, by default it is present in sub/child class. Example:

class Parent
{
            Parent()
            {
            int i=12;
            System.out.println("i is : "+i);
            }
}
class Child extends Parent
{
            Child()
            {
            int i=8;
            System.out.println("i is : "+i);
            }
}

class DefaultConstructorIsCallAutomatically
{
            public static void main(String args[])
            {
Child t=new Child(); 
            }
}
O/P:
 i is : 12

 i is : 8

No comments:

Post a Comment

Designed By Blogger Templates