Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / June 2007

Tip: Looking for answers? Try searching our database.

mcq

Thread view: 
FX - 31 May 2007 19:09 GMT
Given:
1. class Super {
2. public float getNum() { return 3.0f; }
3. }
4.
5. public class Sub extends Super {
6.
7. }
Which method, placed at line6, causes compilation to fail?
A. public void getNum() { }
B. public void getNum(double d) { }
C. public float getNum() { return 4.0f; }
D. public double getNum(float d) { return 4.0d; }
rossum - 31 May 2007 19:23 GMT
>Given:
>1. class Super {
[quoted text clipped - 9 lines]
>C. public float getNum() { return 4.0f; }
>D. public double getNum(float d) { return 4.0d; }

You forgot to include your instructor's e-mail.  Without that we
cannot send in the answers to your homework.  I am afraid you will
have to do it yourself.

How about trying to compile the four different options provided and
see which one fails?  You never know, you might actually learn
something.

rossum
Andrew Thompson - 31 May 2007 19:24 GMT
Please refrain from multi-posting*, no matter
how urgent your homework is..

* <http://www.physci.org/codes/javafaq.html#xpost>

(X-post to c.l.j.p./h., w/ f-u to c.l.j.h. only)

Andrew T.
Richard Reynolds - 31 May 2007 19:28 GMT
> Given:
> 1. class Super {
[quoted text clipped - 9 lines]
> C. public float getNum() { return 4.0f; }
> D. public double getNum(float d) { return 4.0d; }

Q: Looking at those particular methods, which ones, placed anywhere, should
get you the sack?

A: all of them!
FX - 31 May 2007 19:42 GMT
On May 31, 11:28 pm, "Richard Reynolds" <richiereyno...@ntlworld.com>
wrote:
> > 1. class Super {
> > 2. public float getNum() { return 3.0f; }
[quoted text clipped - 13 lines]
>
> A: all of them!

I tried compiling, all got compiled......
but answer is one of them not all....
Steve Wampler - 31 May 2007 21:38 GMT
> I tried compiling, all got compiled......
> but answer is one of them not all....

Uh, you might want to try those compilations again...

Signature

Steve Wampler -- swampler@noao.edu
The gods that smiled on your birth are now laughing out loud.

JT - 31 May 2007 21:53 GMT
> On May 31, 11:28 pm, "Richard Reynolds" <richiereyno...@ntlworld.com>
> wrote:
[quoted text clipped - 19 lines]
> I tried compiling, all got compiled......
> but answer is one of them not all....

The answer is A.
According to Eclipse

Severity and Description    Path    Resource    Location    Creation Time    Id
The return type is incompatible with test.Super.getNum()    test/test
test.java    line 8    1180644466716    1
Lew - 31 May 2007 22:10 GMT
FX wrote:
>> 1. class Super {
>> 2. public float getNum() { return 3.0f; }
[quoted text clipped - 8 lines]
>> C. public float getNum() { return 4.0f; }
>> D. public double getNum(float d) { return 4.0d; }

> The answer is A.

Well, you should really try javac, and not to do the OP's homework for them.

To the OP:
>>> I tried compiling, all got compiled......
>>> but answer is one of them not all....

Your period key is stuck.

What went wrong?  How come your compilations failed to find the error?

How exactly did you test the compilation?

Let's say you put your source in a directory called "$HOME/project/src/".
Does your test look something like this?

$ cd $HOME/project/src
$ javac Sub.java

Signature

Lew

Patricia Shanahan - 31 May 2007 22:58 GMT
...
> What went wrong?  How come your compilations failed to find the error?
>
[quoted text clipped - 5 lines]
> $ cd $HOME/project/src
> $ javac Sub.java

Also, check what "Super" is for that compilation. Given a pair of
classes "Super" and "Sub" there might be other classes called "Super"
lying around. For most choices of Super, Sub will compile with any of
the choices of inserted line.

Patricia
Andrew Thompson - 01 Jun 2007 03:11 GMT
Please refrain from multi-posting*, no matter
how urgent your homework is..

* <http://www.physci.org/codes/javafaq.html#xpost>

(X-post to c.l.j.p./h., w/ f-u to c.l.j.h. only)

Andrew T.
Phi - 01 Jun 2007 19:07 GMT
FX schrieb:
> Given:
> 1. class Super {
[quoted text clipped - 9 lines]
> C. public float getNum() { return 4.0f; }
> D. public double getNum(float d) { return 4.0d; }

Hy FX
B and D are overloading (not overriding) and so can be easyly compiled.
A and C are overriden methods.
For overriden methods the return type must be the same (float in this case).
So C will compile, but A will not. A is the solution (the only that fails).

For more homework: Check out my program at
http://www.santis.ch/training/java/jcp/selftester/indexe.php

greets
phi


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.