Meaningless Drivel is fun!*
The moose likes Beginning Java and the fly likes overriding isn`t correct? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "overriding isn`t correct?" Watch "overriding isn`t correct?" New topic

overriding isn`t correct?

zhang feng

Joined: Dec 16, 2002
Posts: 19
i have two class below

Now, i compile the class ,but it`s not correct!
i change the class below

it`s run good ,but i dont know why?
thanks for u help!
[ August 03, 2003: Message edited by: zhang feng ]
qingwu wang
Ranch Hand

Joined: Feb 19, 2003
Posts: 147
I think your args in the which must can be cast type of Myclass including args type. I say casttype must be auto.for example int->double vice versa.if args type exist in your SubMyclass then it will run subclass is only a little cue.

Thanks...qingwu<br />When I open my eyes,I see your pretty face.
zhang feng

Joined: Dec 16, 2002
Posts: 19
sorry ,here is a little wrong!
now i repaired myclass.
your means are the JVM will find the subclass method ,if don`t find.
type will be auto to casttype,find parent method!
In the first code , the method fun() called in the main(),because JVM don`t find sample arguement's fun() in the subclass method,cast be auto, the type
cast to higher.but the parent class method's fun() arguement sample in the main() called. now the JVM don`t know invoke which an indeed fun();
r u means?
Francis Siu
Ranch Hand

Joined: Jan 04, 2003
Posts: 867
overriding isn`t correct?
Because the method overriding occurs if the method contains the same method signature including the method name and the parameter list
So that it is method overloading.
For the method overloading, according to your situation, the method of subclass will do the type casting to be a bigger one(int to long 32-->64)
if the subclass can do it,the action will be done if the data size is smaller than the origin.But the action will not be done if data size is bigger than the origin, then,it will search superclass whether contains the same method signature or not.
You can test the following

If it is wrong,please feel free to remind me.

Francis Siu
zhang feng

Joined: Dec 16, 2002
Posts: 19
oh,it`s right ,thank you!!!
I agree. Here's the link:
subject: overriding isn`t correct?
Similar Threads
Long and autoboxing
Overloading makes Difficult using j2se 5
i need help
Mock Question
Primitive Value Assignment