• 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
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

difference

 
Ranch Hand
Posts: 158
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i got a little confused canany one explain

How to identify whether a method from Object is being overriden,overloaded or redeclared in a class with example???

it may be Trivial one but...
 
Ranch Hand
Posts: 127
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by harish shankarnarayan:
i got a little confused canany one explain

How to identify whether a method from Object is being overriden,overloaded or redeclared in a class with example???

it may be Trivial one but...



Overridden - identical method signature in base and derived classes
Ex. public int multiply(int a, int b) {return a*b}

Overloaded - different method signature in base and/or derived classes
Ex. public int multiply(int a, int b) {return a*b;}
public int multiply(int a, double b) {return a*b;}
public int multiply(int a, int b, int c) {return a*b*c;}

I am unsure what you mean by "redeclared" in a class. (Note that the second method will compile with a loss of precision warning)
[ February 01, 2006: Message edited by: Chris Allen ]
 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If the base class method say meth() is private and you define a new method that has the same signature as meth() that is in base class. you have defined a new method in sub-class . Since the names are sane i guess this wat is known as redeclaration.
However the compiler will flag an error if any attempt is made to redeclare a method that is not overloaded.
bye
deepu
 
Ranch Hand
Posts: 584
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Rules for overriding methods

1. The argument list must exactly match that of the overridden method.
2.The access level CAN'T be more restrictive than the overridden method.
3.The access level CAN be less restrictive than that of the overridden method.
4.The overriding method CAN throw any unchecked (runtime) exception,
regardless of whether the overridden method declares the exception.
5.The overriding method must NOT throw checked exceptions that are new
or broader than those declared by the overridden method.

Rules for overloading methods
1.Overloaded methods MUST change the argument list.
2.Overloaded methods CAN change the return type.
3.Overloaded methods CAN change the access modifier.
4.Overloaded methods CAN declare new or broader checked exceptions.
5.A method can be overloaded in the same class or in a subclass.
 
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