• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Get the hidding overridden method...

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi everyone,

Suppose we have the following:
class A {
void aMethod(){
...
}
}

class B extends A{
void aMethod(){
... //overriding aMethod from A
}
}

class C extends B{
void aMethod(){
... //overriding aMethod from B
}
}

How can I make a call to method the aMethod of A?

Best regards,
Anders
 
Ranch Hand
Posts: 1608
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It can't be done.
An overridden method is overridden and overridden has a precise meaning.
 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Suppose we have the following:
class A {
void aMethod(){
...
}
}

class B extends A{
void aMethod(){
... //overriding aMethod from A
}
}

class C extends B{
void aMethod(){
... //overriding aMethod from B
}
}

from class C you can call class B's aMethod by using super.aMethod...
similarly you can call from class B you can call class A's aMethod using super.aMethod... but you cannot call(in this case) from class C , the aMethos of class A directly!!like super.super.aMethod!!WRONG!!

thus in case of overriding, you can call only to one level up.... directly by using super.<method name>
 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In addition, you can call the the function using the main method.

class A {

A()
{
}

void aMethod()
{
System.out.println("i m in A");

}
}

class B extends A{
void aMethod(){
//overriding aMethod from A
System.out.println("i m in B");
}
}

class C extends B{
void aMethod(){
System.out.println("i m in C");
//overriding aMethod from B
}
}

class overwrite
{
public static void main( String args[])
{
A a = new A( ) ;
a.aMethod( );
}
}
 
Ranch Hand
Posts: 195
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Anders, another option is to call the A method from the C method by creating an instance of A within the C method, like this:

 
ADSWED
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am starting to believe that a C object never can use the aMethod of A.

Thank you! ;o)
 
Message for you sir! I think it is a tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic