File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Question on Construtor Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Question on Construtor " Watch "Question on Construtor " New topic
Author

Question on Construtor

Ram Reddy
Ranch Hand

Joined: Feb 20, 2007
Posts: 88
Source : http://www.jchq.net
a) A Constructor may not be declared as private
b) A Constructor with no arguments will be the default constructor
c) Constructors cannot be overloaded
d) A call to constructor in a parent class can only be made from with in a
constructor

For the above question, i marked b) as the correct answer.
But they have given d) is the correct answer.

class Super
{
Super(){}
}
class Sub extends Super
{
Sub()
{
Super();
}
public void submethod()
{
Super super = new Super();// making call to super constructor
}
}

We are making call to Super() constructor in submethod() method.
Then option d) is wrong. Is this question cannot refer the above?

Rami
kapil kumar
Greenhorn

Joined: May 22, 2008
Posts: 25
Source : http://www.jchq.net
a) A Constructor may not be declared as private
b) A Constructor with no arguments will be the default constructor
c) Constructors cannot be overloaded
d) A call to constructor in a parent class can only be made from with in a
constructor

For the above question, i marked b) as the correct answer.
But they have given d) is the correct answer.

class Super
{
Super(){}
}
class Sub extends Super
{
Sub()
{
Super();
}
public void submethod()
{
Super super = new Super();// making call to super constructor
}
}

We are making call to Super() constructor in submethod() method.
Then option d) is wrong. Is this question cannot refer the above?

Rami



Hi Ram...
Here b cannnot be the answer because
The default constructor is no-arg constructor is true..
But the no arg constructor is not the default constructor..

You can only call the superclass constructor from the sub class constructor and it should be the first statement inside the subclass constructor...

Super super = new Super();// making call to super constructor

Here you are creating an object of class Super new Super() and not calling super();

Super super = new Super();// making call to super constructor

This line also won't compile since super is a keyword and cannot be used as an identifier.....
Hope this clears your doubt...

Correct me if I am Wrong......


If you can't be the Sun ..<br /> Be a star ..............
Ram Reddy
Ranch Hand

Joined: Feb 20, 2007
Posts: 88
thanks kapil.
that cleared my doubt.
by hand i have written the code. So by mistake i typied super.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Question on Construtor
 
Similar Threads
Super
Constructor in parent class
a certain bug i cant understand..
A simple Q but still have doubt
from abhilash - constructors