aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Question on Dan's Mock 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 "Question on Dan Watch "Question on Dan New topic
Author

Question on Dan's Mock

Murtuza Akhtari
Ranch Hand

Joined: Aug 07, 2004
Posts: 108

Answers : d,e,f

I understand the d and the e...but why is it a compiler error at line 4
Also the explanation to the answer is as follows:

At line 2, the statement, "return i;", contains the expression, i. The enclosing method, m2, is declared void. The return statement generates a compile-time error, because it contains an expression. At line 3, the statement, "return;", does not contain an expression. The enclosing method, m3, is declared with the result type, int. The return statement generates a compile-time error, because it does not contain an expression that produces a value that is assignable to the declared result type.

Thanks
[ August 14, 2004: Message edited by: Murtuza Akhtari ]

---<br />SCJP 1.4
Francis Siu
Ranch Hand

Joined: Jan 04, 2003
Posts: 867
hi Murtuza Akhtari
The enclosing method, m3, is declared with the result type, int. The return statement generates a compile-time error, because it does not contain an expression that produces a value that is assignable to the declared result type.

I can explain more aove statement, m3 is declered as a method and it will return an integer after invoked, but please notice the method body, it does not produce a value { return;} that matches the return type of method static int m3(....).... So, compile-time error occured.


Francis Siu
SCJP, MCDBA
Dan Chisholm
Ranch Hand

Joined: Jul 02, 2002
Posts: 1865
Murtuza,

At line 4, the print statement attempts to print the return values of the methods, but method m2 has a void return type.


Dan Chisholm<br />SCJP 1.4<br /> <br /><a href="http://www.danchisholm.net/" target="_blank" rel="nofollow">Try my mock exam.</a>
 
 
subject: Question on Dan's Mock