zhaobin74

Greenhorn
+ Follow
since Sep 26, 2000
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by zhaobin74

Considering the following code:
class Point{
void aMethod(int f){
int var = f;
System.out.println("This is the superclass"+var);
}
}
public class Subpoint extends Point{
public static void main(String[] args){
Point s=new Subpoint();
s.aMethod(2.1f);
}
void aMethod(float f){
float var = f;
System.out.println("this is subclass"+var);
}
}
when compiled, error" aMethod(int) can not be applied to (float)
s.aMethod(2.1f);" occurs
I am confused about,since s references a Subpoint object,why does't compiler invoke aMethod(float) defined in Subpoint class without error?
I remember that when invoke an instance method, the method defined in the class whose object is being referenced will be invoked.
Am I wrong?
Thanks for all replies.
Both are incorrect castings.
See JLS 5.5
there are detailed information for casting conversion
I mean,having no CS background and with a SCJP2 Cert.,
can I find a Java-related job in USA?
b) is right. equals() compare the content of Strings.
Since "new" will create new objects and "==" compares 2 reference to see it they point to the same object,a) and c) are wrong.
I am not very clear why d) is wrong.