• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Overloading, overriding, runtime type, and object orientations

 
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi Friends ,,,,,
I feel not ok with Overloading, overriding, runtime type, and object orientations
Any body can help me to do better in this section
And what is object orientations contents
TIA
tony
 
Ranch Hand
Posts: 2120
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Compile (declared) type: any expression in Java has a type known by the compiler
Object o = new Integer();
the declared type of the variable o is Object.
Runtime: the real type of an object is only known by the "interpreter" --because the object is created only when the program is executing. The (runtime) type of the object pointed by o is Integer.
Overloading: several methods with the same name has a different list of paremeters. The compiler yields error if they have the same name and the same list of parameters.
Because overloding methods are really different methods, there is not relationship between their return types. There is not relationship between their exception throws clauses either.
Overloading is possible also among a class and its subclass:
Object.toString()
Integer.toString(int)
Integer.toString(int, int)
All of them are overloading methods.
Overloading gets that methods that should have the same name, because they perform a similar operation on distinct paramers, can be equally named. You do not have to made up a different name for each combination of parameters.

Overriding: (the magic of polymorphism)
An instance method is declared in a class
Object.toString() (overridden)
An instance method is declared in a subclass. It has the same name, return type and argument list than the one in its superclass. It can declare any checked exception that was declared in the superclass, or any of its subexceptions. But it cannot declare any other checked exception.
Integer.toString() (overridding)
Hmm... same name, return type, argument list and conforms to declared checked exceptions. I would say both methods are the same. Yes they are, they really apply the same operation to father-son objects.
The operation is the same, but the implementation of the methods vary according to the runtime/real type of the object. Not the declared type of the variable that points the object:
Object o = new Object();
o.toString()
will call the method toString declared in Object, while
Object o = new Integer();
o.toString()
will call the method toString declared in Integer.
The overriding method Integer.toString has specialized the implementation of Object.toString to adjust the print operation when invoked on an Integer instance. This is polymorphism, the same name/operation (toString/printing) applied to hierarquically related objects, but adjusted to the nature of them. Also known as behaviour dependent on type.
 
tony kanvas
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks jose
We can say this is lecture
Thanks for your time
 
tony kanvas
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I got one post they said in this section 20 questions from exam will be in
Is this true from one section will be 20 questions
 
We're all out of roofs. But we still have tiny ads:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic