Results 1 to 3 of 3
  1. #1
    satheeshtech is offline Member
    Join Date
    Jul 2009
    Posts
    18
    Rep Power
    0

    Default how to call higher level super class method?

    Class B extends class A
    and Class C extends Class B
    all 3 classes have instance method method1().

    how to invoke class A's method1() from class c ( except A a=new A(); a.method1() )

  2. #2
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    7

    Default

    Why? What is the problem you are trying to solve?

  3. #3
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,436
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by satheeshtech View Post
    Class B extends class A
    and Class C extends Class B
    all 3 classes have instance method method1().

    how to invoke class A's method1() from class c ( except A a=new A(); a.method1() )
    You can't do that, the "super.method( ... )" construct finds the nearest super class that implements "method( ... )"; you need a "trampoline":

    Java Code:
    class A { 
       public void method() { ... }
    }
    
    class B extends A {
       public void method() { ... }
       public void superMethod() { super.method(); } // trampoline
    }
    
    class C extends B {
       public void method() { ... }
       public void superMethod() { super.method(); } // trampoline
    
    }
    kind regards,

    Jos

Similar Threads

  1. How to call a method from another class?
    By jboy in forum New To Java
    Replies: 8
    Last Post: 09-09-2009, 07:29 AM
  2. [SOLVED] Class-level vs Object-level method()
    By mfaizan24 in forum New To Java
    Replies: 7
    Last Post: 06-23-2009, 09:18 AM
  3. How to call a class within a method
    By Manfizy in forum New To Java
    Replies: 3
    Last Post: 03-19-2009, 12:34 PM
  4. [SOLVED] Call method from another class name
    By antgaudi in forum New To Java
    Replies: 3
    Last Post: 10-15-2008, 12:33 AM
  5. Class Reflection: Finding super class names
    By Java Tip in forum java.lang
    Replies: 0
    Last Post: 04-23-2008, 08:12 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •