This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes interesting behavior Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "interesting behavior" Watch "interesting behavior" New topic
Author

interesting behavior

Kirti Dhingra
Ranch Hand

Joined: Dec 13, 2000
Posts: 32
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
rajani peddi
Ranch Hand

Joined: Nov 27, 2000
Posts: 73
In the first case the method is being ovverriden and in the second case its not. Hence the behaviour.
bill bozeman
Ranch Hand

Joined: Jun 30, 2000
Posts: 1070
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().
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: interesting behavior
 
Similar Threads
how to appendReplace multiple values in java.util.regex
Generic wildcard lower bound (bug or erratum?)
Bisection Method
EPractice Labs - Wrong answer????
Reading and writing fixed length file