wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Mock Exam 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 "Mock Exam" Watch "Mock Exam" New topic
Author

Mock Exam

Sunder Rohini
Greenhorn

Joined: Sep 01, 2003
Posts: 4
public class Question24 {
public static void main(String[] args){
Question24 q24 = null;
int i = q24.throwDice(); //line 1
int j = getDice().throwDice(); //line 2
System.out.println("Result: "+i+","+j);
}
private static int throwDice(){
return 1+(int)(Math.random()*6);
}
private static Question24 getDice(){
return null;
}
}
I am unable to understand how getdice().throwdice would work ?
I have been coming across code with only one method to invode with its name.
This is confusing . How the invocation takes place here? Could anybody
enlighten in this regard .
Steve Lovelace
Ranch Hand

Joined: Sep 03, 2003
Posts: 125
I'm not sure what you mean by
This spares us writing something like:

But the main thrust of the question is not about chaining - it is about this code compiling and running even though the references involved all contain null. This works because the methods are static, and so their calls are resolved (bound) by the compiler based purely on reference type. At runtime, it doesn't matter what the references contain.
[ September 06, 2003: Message edited by: Steve Lovelace ]

The Inner that is named is not the true Inner.
Sunder Rohini
Greenhorn

Joined: Sep 01, 2003
Posts: 4
Thanks Steve
 
 
subject: Mock Exam