Win a copy of Pipeline as Code this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Rob Spoor
  • Henry Wong
  • Liutauras Vilda
Saloon Keepers:
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
Bartenders:
  • Frits Walraven
  • Himai Minh
  • Jj Roberts

overriding isn`t correct?

 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Ranch Hand
Posts: 147
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think your args in the sub.fun() 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 method.it is only a little cue.
 
zhang feng
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Ranch Hand
Posts: 867
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
overriding isn`t correct?
isn't
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.
 
zhang feng
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
oh,it`s right ,thank you!!!
 
Not looking good. I think this might be the end. Wait! Is that a tiny ad?
SKIP - a book about connecting industrious people with elderly land owners
https://coderanch.com/t/skip-book
reply
    Bookmark Topic Watch Topic
  • New Topic