It's not a secret anymore!*
The moose likes Certification Results and the fly likes doubt on constructors Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Certification » Certification Results
Reply locked New topic
Author

doubt on constructors

sonir shah
Ranch Hand

Joined: Nov 01, 2001
Posts: 435
I came across a question in the mock
It is as under :
class A {
A() {
System.out.println("Class A Constructor");
}
}
public class B extends A {
B() {
System.out.println("Class B Constructor");
}
public static void main(String args[]) {
B b = new B();
}
}
// the output here is "Class A Constructor followed by Class B Constructor //
again similar question i came across.It is as under :

class A {
A(double d) {
System.out.println("Printing the value of d is 10");
}
}
public class B extends A {
B() {
System.out.println("Class B Constructor");
}
public static void main(String args[]) {
B b = new B();
}
}
[a] Printing the value of d is 10 followed by Class B Constructor
[b] Printing the value of d is 10
[c] Compile time error
[d] Run time error
//The output here is Complile Time Error..
Can any one explain me the diffrence between the two??
Fei Ng
Ranch Hand

Joined: Aug 26, 2000
Posts: 1242
go back to http://www.javaranch.com/ubb/Forum24/HTML/013276.html
Why post same question on two fourm??
Valentin Crettaz
Gold Digger
Sheriff

Joined: Aug 26, 2001
Posts: 7610
Cross posting is BAD
I'm closing this thread
------------------
Valentin Crettaz
Sun Certified Programmer for Java 2 Platform


SCJP 5, SCJD, SCBCD, SCWCD, SCDJWS, IBM XML
[Blog] [Blogroll] [My Reviews] My Linked In
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: doubt on constructors