mcq

F

FX

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; }
 
R

rossum

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; }

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
 
R

Richard Reynolds

FX said:
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; }
Q: Looking at those particular methods, which ones, placed anywhere, should
get you the sack?

A: all of them!
 
F

FX

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

A: all of them!

I tried compiling, all got compiled......
but answer is one of them not all....
 
J

JT

FX said:
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
 
L

Lew

The answer is A.

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

To the OP:
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
 
P

Patricia Shanahan

Lew wrote:
....
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

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
 
P

Phi

FX said:
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; }

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top