File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Question from go4java mock

 
Leandro Melo
Ranch Hand
Posts: 401
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Which one of the following methods will give you an error when placed at
line no.10? Select one correct answer.



Options for answer:
1. public final void callme(){}
2. void callMe(){}
3. void callme(int a){}
4. void callme(){}


None of this options generated an error in my jdk (1.4). Can anyone clearify this to me?
 
ramaseshan T
Ranch Hand
Posts: 30
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


1. public final void callme(){}
2. void callMe(){}
3. void callme(int a){}
4. void callme(){}


None of this options generated an error in my jdk (1.4). Can anyone clearify this to me?


1. Way to override callme method - No compiler error
2. Note "M" in callMe - It is a overloaded method - No error
3. Again it is perfect overloading - No error
4. Generates compiler error in JDK 1.4 - since it is declared with lesser access previleges

Please correct me if I am wrong...
 
ankur rathi
Ranch Hand
Posts: 3830
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by ramaseshan T:


2. Note "M" in callMe - It is a overloaded method - No error
Please correct me if I am wrong...



It is not overloading method , it is whole together new method .
everything else is right .
 
Charles Chen
Greenhorn
Posts: 5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Leandro Melo:
Which one of the following methods will give you an error when placed at
line no.10? Select one correct answer.



Options for answer:
1. public final void callme(){}
2. void callMe(){}
3. void callme(int a){}
4. void callme(){}


None of this options generated an error in my jdk (1.4). Can anyone clearify this to me?


I will say no.4. I think it is not a overload method nor override method.
 
Carol Enderlin
drifter
Ranch Hand
Posts: 1364
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
#4 gives compiler error for me:

C:\_Work\java>javac A.java
A.java:10: callme() in B cannot override callme() in A; attempting to assign weaker access privileges; was public
void callme(){}
^
1 error

C:\_Work\java>java -version
java version "1.4.1_05"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1_05-b01)
Java HotSpot(TM) Client VM (build 1.4.1_05-b01, mixed mode)
 
Kedar Dravid
Ranch Hand
Posts: 333
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The answer to the question is option no.4, because we are trying to override the callme() method with a weaker access privilege. Period.
 
Leandro Melo
Ranch Hand
Posts: 401
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry, of course it generates a error. I tested it wrong.
Thanks.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic