my dog learned polymorphism
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Doubts  from  javaprepare sample test Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Doubts  from  javaprepare sample test" Watch "Doubts  from  javaprepare sample test" New topic

Doubts from javaprepare sample test

Renuka Kilambi

Joined: Apr 21, 2000
Posts: 23
In the below question from the java prepare test , My answer was
a and c.But in the key the answer is given as a,c,d. How come? A class Constructor may have keyword private also.Am I wrong?An explanation is highly appreciated.
Q. Which of the following is correct ? Select all correct answers.

a.The native keyword indicates that the method is implemented in another language like C/C++.
b.The only statements that can appear before an import statement in a Java file are comments.
c.The method definitions inside interfaces are public and abstract. They cannot be private or protected.
d.A class constructor may have public or protected keyord before them, nothing else.
Ranch Hand

Joined: Jul 20, 2000
Posts: 112
Hi Renuka,
U are absolutely correct. A class can have public / private / protected constructors
A class can be designed to prevent code outside the class declaration from creating instances of the class by declaring at
least one constructor, to prevent the creation of an implicit constructor, and declaring all constructors to be private.
See the follwing code
class Base{
private Base(){
System.out.println("Private Base Constructor");

public class Test extends Base {
System.out.println("Child Constructor");
public static void main (String args []) {
new Test();
This code gives compilation error No constructor matching base() found in class Base. Test(){

Because a class having a private constructor can't be instantiated (here Test is a form of base).
Hope this clears your doubt.
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Pls. anyone can explain for the second question.
maha anna
Ranch Hand

Joined: Jan 31, 2000
Posts: 1467
For the question Renuka posted above , the option d) is NOT valid. We can very well have private constructors for a class. So let us move this thread to our 'Mock Exam Errata'.
Before that, Surya, I am not sure of what you ask. Can you rephrase your qstn? Are you talking about another qstn in If so please start another NEW THREAD so that it is easy for us to move this thread to Errata Forum. I will close this thread after confirmation from you.Thank you.
maha anna
[This message has been edited by maha anna (edited July 21, 2000).]
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
I am sorry I misunderstood that this second question is same one of mine which is another thread.
Sorry for any inconvenience.
Thanks for your reply.
Consider Paul's rocket mass heater.
subject: Doubts from javaprepare sample test
jQuery in Action, 3rd edition