Forums Register Login

interesting behavior

+Pie Number of slices to send: Send
class upper{
void ft(){
System.out.println("upper ft");
}
void gt(){
System.out.println("upper gt");
}
}
class lower extends upper{
void ft(){
System.out.println("lower ft");
}
public static void main(String args[]){
upper c=new lower();
((upper)c).ft();
((upper)c).gt();
}
}
output is is
lower ft
upper gt
+Pie Number of slices to send: Send
In the first case the method is being ovverriden and in the second case its not. Hence the behaviour.
+Pie Number of slices to send: Send
Your cast (upper)c is redundant since you already upcasted this to upper when you said:
upper c = new lower();
You are going to get the overridden methods since c is really a lower().
30 seconds to difuse a loaf of bread ... here, use this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 528 times.
Similar Threads
Reading and writing fixed length file
Bisection Method
Generic wildcard lower bound (bug or erratum?)
how to appendReplace multiple values in java.util.regex
EPractice Labs - Wrong answer????
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 09:48:21.