• Post Reply Bookmark Topic Watch Topic
  • New Topic

Overloading or Overriding  RSS feed

 
Mohnish Khiani
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
class ex1
{
void meth(Object o)
{
System.out.println("ex1");
}
}
class ex2 extends ex1
{
void meth(String o)
{
System.out.println(o);
}
}
 
Wouter Oet
Bartender
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Good question. In this case you're overloading. To override you must have the same function name and parameters and the return type must be of the same class or a sub-class of it. A good test is to annotate your overriding functions with the @Override annotation. If you're not overriding anything then the compiler will complain.

// Edit: and please UseCodeTags when posting code
 
Mohnish Khiani
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply....what is a codetag?
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is a good exercise.

If the method is overridden, how would it behave? you should be able to write code to demonstrate this, and the output will answer your question.
 
Greg Charles
Sheriff
Posts: 3015
12
Firefox Browser IntelliJ IDE Java Mac Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mohnish Khiani wrote:Thanks for the reply....what is a codetag?


They are a way of automatically formatting code samples to make them easier to read. See the link below:

Use Code Tags
 
Rob Spoor
Sheriff
Posts: 21131
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also, sometimes you see a little dotted line under one or more words. That means it's an automatically generated link, mostly to a Javadoc page or an FAQ entry. Check out Wouter's post to see it.
 
Shanky Sohar
Ranch Hand
Posts: 1051
Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Remember ro check for overloaded methods,
When the arguments types are different that means the methods are overloaded.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!