Results 1 to 1 of 1
-
Calling constructor of parent class from a constructor
The following example shows how to call constructor of parent class. Calling the constructor for the superclass must be the first statement in the body of a constructor.
Java Code:public class ClassSuper { public ClassSuper(){ System.out.println("Constructor of ClassSuper called."); } } public class ClassA extends ClassSuper{ public ClassA(){ super(); System.out.println("Constructor without parameter."); } public static void main(String[] str) { ClassA obj = new ClassA(); } }
Java Code:Constructor of ClassSuper called. Constructor without parameter.
Similar Threads
-
Beginner; Create a class to store info and constructor to initialize
By badness in forum New To JavaReplies: 16Last Post: 05-08-2008, 10:45 PM -
Constructor calling
By ravian in forum New To JavaReplies: 2Last Post: 12-22-2007, 07:53 PM -
Calling constructor of same class from a constructor
By Java Tip in forum Java TipReplies: 0Last Post: 12-19-2007, 10:01 AM -
Constructor Help
By bluegreen7hi in forum New To JavaReplies: 2Last Post: 11-15-2007, 06:44 AM
Bookmarks