• Post Reply Bookmark Topic Watch Topic
  • New Topic

Overriding  RSS feed

 
Ramakrishna Gummadi
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the use of OVERLOADING and OVERRIDING ?

 
ankittt agarwala
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
  • Quote
  • Report post to moderator
ok ok you want to see its use go here.
 
Aniela Kącka
Greenhorn
Posts: 6
Hibernate Java Spring
  • Mark post as helpful
  • send pies
  • 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 .
 
Aditya Jha
Ranch Hand
Posts: 227
Eclipse IDE Java Spring
  • Likes 2
  • Mark post as helpful
  • send pies
  • 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.
 
Campbell Ritchie
Marshal
Posts: 56599
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Aditya Jha wrote: . . .
That's overriding working for you.
. . .
That's overloading working for you.
Nice answer
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!