• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Doubts from javaprepare sample test

 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
Renuka
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
Posts: 112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 {
Test(){
System.out.println("Child Constructor");
}
public static void main (String args []) {
new Test();
}
}
This code gives compilation error
Test.java:8: 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.
Aruna.
 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Pls. anyone can explain for the second question.
 
Ranch Hand
Posts: 1467
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 javaprepare.com. 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.
regds
maha anna
[This message has been edited by maha anna (edited July 21, 2000).]
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
That new kid is a freak. Show him this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic