• 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
  • Ron McLeod
  • Junilu Lacar
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Piet Souris
  • Carey Brown
  • Stephan van Hulst
Bartenders:
  • Frits Walraven
  • fred rosenberger
  • salvin francis

Overriding

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is the use of OVERLOADING and OVERRIDING ?

 
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Overriding - same method names with same arguments and same return types associated in a class and its subclass.
Example:

class CSuper

{

null print ( string _name)
{

print "Hello" + _name;

}

};

class CDerived

{

null print ( string _name)
{

print "Hello" + _name + "from Derived";

}

};



Overloading - same method name with different arguments, may or may not be same return type written in the same class itself.

Example:

class CClass
{

string print( int i);

string print(int i, char c);

};


there is a difference between these two and also when you write programs you will get to know their use too.
Read more: http://wiki.answers.com/Q/Difference_between_overriding_and_overloading#ixzz1UeNV7W7y
 
Ramakrishna Gummadi
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

ankittt agarwala wrote:Overriding - same method names with same arguments and same return types associated in a class and its subclass.
Example:

class CSuper

{

null print ( string _name)
{

print "Hello" + _name;

}

};

class CDerived

{

null print ( string _name)
{

print "Hello" + _name + "from Derived";

}

};



Overloading - same method name with different arguments, may or may not be same return type written in the same class itself.

Example:

class CClass
{

string print( int i);

string print(int i, char c);

};


there is a difference between these two and also when you write programs you will get to know their use too.
Read more: http://wiki.answers.com/Q/Difference_between_overriding_and_overloading#ixzz1UeNV7W7y



Dude.... i know syntactically what is overloading and overriding...

Im asking that show me the use of the overriding in practically..
 
Ramakrishna Gummadi
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Dude.... i know syntactically what is overloading and overriding...

Im asking that show me the use of the overriding in practically..

Show me one program using overrding{use should be there}
 
ankittt agarwala
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ok ok you want to see its use go here.
 
Greenhorn
Posts: 6
Hibernate Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You use overriden method, when you want your subclass to do something in a different way than the superclass in the same method. For example, if you have Animal class and the makeSound() method that will just print out "making sound", then after if you create Cat class which extends the Animal, you surely want the objects of class Cat make another sound, like "miaaaaaaaaaau!!". In such cases you override the method makeSound() in the Cat class.

Overloaded method you use, when you need another method with the same name, but taking different list of arguments... I think the use of it is quite obvious... While the post above had given you a nice example of overriding, I'm giving the example use of overloading here, Dude .
 
Ranch Hand
Posts: 227
Eclipse IDE Spring Java
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have you ever called toString() on any class other than java.lang.Object?

That's overriding working for you.

Have you ever instantiated Integer class using 2 different ways?

That's overloading working for you.
 
Marshal
Posts: 73252
332
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Aditya Jha wrote: . . .
That's overriding working for you.
. . .
That's overloading working for you.

Nice answer
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic