aspose file tools*
The moose likes Mock Exam Errata and the fly likes how is this answear correct? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Mock Exam Errata
Bookmark "how is this answear correct?" Watch "how is this answear correct?" New topic
Author

how is this answear correct?

umesh atada
Greenhorn

Joined: Jun 14, 2001
Posts: 25
Question found in one of the mock exam?
1. class MyClass {
2. public float getNum() {
3. return 1.2f;
4. }
5. }
6. public class YourClass {
7. public ______ getNum() {
8. return 3;
9. }
10. }
What should be entered in the blank on line 7 that will allow compilation to succeed?
CORRECT ANSWEAR GIVEN IS "float".
but i feel it is "int"
What do u feel?
Asma Zafar
Ranch Hand

Joined: May 11, 2001
Posts: 49
Yes, i also thimk its an int.
I don't find any reason for it to be float, becuse the 2 classes r not related in any way.


Asma Zafar,<BR>Sun Certified Programmer for Java2 Platform
Jane Griscti
Ranch Hand

Joined: Aug 30, 2000
Posts: 3141
Hi umesh,
'float' and 'int' would both work; although, based on the returned value an 'int' makes more sense.
------------------
Jane Griscti
Sun Certified Programmer for the Java� 2 Platform


Jane Griscti
SCJP, Co-author Mike Meyers' Java 2 Certification Passport
Rehan Malik
Ranch Hand

Joined: Jul 09, 2001
Posts: 76
My first thought was "int" as well.
However, the ONLY possible reason which it MIGHT be "float" is that it's attempting to override the getNum() function but since it doesn't mention any of this, my first instinct would still have been "int"


Rehan Malik
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
short and byte will work, too.


Associate Instructor - Hofstra University
Amazon Top 750 reviewer - Blog - Unresolved References - Book Review Blog
Muhammad Farooq
Ranch Hand

Joined: May 08, 2001
Posts: 356
As the method "return 3", how can it be other than byte, short, or int??
--Farooq


Muhammad Farooq<br />Sun Certified Programmer for Java 2 Platform<br />Oracle8i Certified Professional Database Administrator
Snylt Master
Ranch Hand

Joined: Jul 07, 2001
Posts: 55
I dunno but it can. The system makes a cast to 3.0!
can anyone explain this?


Preparing for the Java 2 Certification exam
Jane Griscti
Ranch Hand

Joined: Aug 30, 2000
Posts: 3141
Hi SynIt Master,
Your right, widening conversion comes into play, they system will just convert the '3' to '3.0f'.
Looking at the question again, it's not quite clear what's being tested At first I thought it was related to overriding, in which case the return value must be the same but YourClass does not extend MyClass. I'm not sure where the question came from but all in all IMHO it seems a rather pointless one

------------------
Jane Griscti
Sun Certified Programmer for the Java� 2 Platform
Jane Griscti
Ranch Hand

Joined: Aug 30, 2000
Posts: 3141
SynIt Master,
Please read the JavaRanch Name Policy and re-register using a name that complies with the rules.
Thanks for your cooperation.
------------------
Jane Griscti
Sun Certified Programmer for the Java� 2 Platform
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how is this answear correct?