Results 1 to 4 of 4
  1. #1
    magesh5 is offline Member
    Join Date
    Oct 2010
    Posts
    3
    Rep Power
    0

    Arrow I need solution for this program

    Hi,

    I need solution for this program..

    Without refer super() method in class B,
    I want to access method() in the class A.


    Example:-
    ******

    class A
    {

    public void method()
    {
    System.out.println("Call A");
    }
    }

    class B extends A
    {
    public void method()
    {
    System.out.println("Call B");
    }
    }

    public class ExtendsMak extends B{

    public void get()
    {
    super.equals(getClass());
    }
    public static void main (String args[])
    {
    ExtendsMak ek = new ExtendsMak();
    ek.get();


    }

    }

    Rule:-
    ----
    I need to call a method in class A, without any super() reference in class B..

    Method will call through main class object of [ ek]

    Give some Suggestion for this...
    thank in advance...

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,450
    Rep Power
    18

    Default

    You can't since they both have the same name, class B's method() overrides class A's.
    The only way is for a call into class B that uses super.

  3. #3
    magesh5 is offline Member
    Join Date
    Oct 2010
    Posts
    3
    Rep Power
    0

    Default

    Is there any other way i can call both method() using object of main class without reference super() in class B.

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,450
    Rep Power
    18

    Default

    No.
    Well, there may be tricks via reflection, I don't know. But if you find yourself needing that then you should review your design, because that's rubbish.

    Put simply, if you want your B to be an A then it should be an A and not a B. If you want it to be both then you need to come up with some sensible model that will allow that without tying yourself in knots.

Similar Threads

  1. Comments on my FPS solution
    By trader5050 in forum New To Java
    Replies: 1
    Last Post: 11-17-2010, 04:51 PM
  2. Probably a simple solution
    By Collinryans in forum New To Java
    Replies: 6
    Last Post: 06-27-2010, 03:36 AM
  3. Please I need the solution to this
    By debobbt in forum New To Java
    Replies: 4
    Last Post: 12-18-2009, 04:34 AM
  4. solution for my project
    By shkelqa in forum AWT / Swing
    Replies: 4
    Last Post: 05-28-2008, 10:31 PM
  5. Please need solution
    By prithvi in forum New To Java
    Replies: 4
    Last Post: 04-22-2008, 01:27 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
  •