Results 1 to 2 of 2
- 09-24-2010, 01:24 PM #1
y superclass constructor is called automatically
In this program when the red line is executed the constructor of class B is supposed to be called Only as far as I know........ but the constructor of super class is also called. y??????????????Java Code:class A { A() { System.out.println("Class : A"); } } class B extends A{ B() { System.out.println("Class : B"); } } public class Myclass { public static void main(String[] args) { [COLOR="Red"]new B();[/COLOR] } }“Give somebody a fish and they eat for a day.Teach somebody to fish they eat for life!”
- 09-24-2010, 01:58 PM #2
Guys I got the answer. Thnx n e ways :)
If a constructor does not explicitly invoke a superclass constructor, the Java compiler automatically inserts a call to the no-arguement constructor of the superclass. If the super class doesnot have a no-arguement constructor, you will get a compile-time error.“Give somebody a fish and they eat for a day.Teach somebody to fish they eat for life!”
Similar Threads
-
called external program does not automatically write file
By nickvandewiele in forum New To JavaReplies: 6Last Post: 02-25-2010, 02:38 PM -
My constructor not called
By rdtindsm in forum New To JavaReplies: 2Last Post: 09-20-2009, 01:38 AM -
Calling constructor of parent class from a constructor
By Java Tip in forum Java TipReplies: 0Last Post: 12-19-2007, 09:10 AM -
Calling constructor of same class from a constructor
By Java Tip in forum Java TipReplies: 0Last Post: 12-19-2007, 09:01 AM -
Getting name of superclass (Example: ArithmeticException)
By Java Tip in forum Java TipReplies: 0Last Post: 11-12-2007, 11:53 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks