• 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
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

whether the eg overrides or overloads

 
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,
i've some doubt regarding the following eg

class A
{
protected metha()
{...}
}
class B extends A
{
private metha()
{....}
}

whether method in class B overrides/overloads method in class A.

Thank you in advance.
 
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry mate, it does neither - it'll throw an exception.
 
Praveen palukuri
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
may i know the reason to cause exception.
 
Ranch Hand
Posts: 209
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear Praveen,
Over-riding: This is done when you provide a different implementation of a method (belonging to a super-class) in your class. This over-riding method should have the same signature as your superclass method. And along with that the access modifier that you specify for the over-riding method should have a scope equal to OR higher than the superclass method.
Hope I am not confusing matters here.
As you can see from the example you provided, the method in your subclass had a scope smaller than the superclass, so the compiler throws an error.
Over-loading: This is done when the method signature is the same but either of the following conditions should be met:
  • the number of parameters is different
  • the order of the parameters are different
  • the type of parameters are different


  • I have a feeling I have written a lot of information that may be incorrect. So just wait until an expert comes in and verifies the information. I just wrote my understanding of Overloading/Over-riding methods.
    [ April 20, 2006: Message edited by: Shyam Murarka ]
     
    Ranch Hand
    Posts: 75
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Hi praveen,

    your metha() in class B is (trying to) override the metha() in class A. Overloading is when you declare a method with the same name but a different signature (e.g.metha(int a) ).

    Anyway, in yuor example it would not work : you cannot reduce the visibility of a method when you override it (and private is a "smaller" visibility than "protected").

    => you would get a compile time error

    Cheers
     
    Ranch Hand
    Posts: 1026
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator


    Sorry mate, it does neither - it'll throw an exception.



    WRONG.

    It will NOT throw a runtime exception.

    You will get compile time error stating weaker access privilege
     
    author and iconoclast
    Posts: 24207
    46
    Mac OS X Eclipse IDE Chrome
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Unfortunately, this mistake is an all too common one: referring to compile errors as "exceptions."
     
    Alana Sparx
    Ranch Hand
    Posts: 121
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    I consider my slack, slapdash and lackadaisical attitude to semantics duly chastised and promise to sharpen up my attitude forthwith.

    Basically dude, it isnae gonnae wurk.
     
    With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
    reply
      Bookmark Topic Watch Topic
    • New Topic