Results 1 to 4 of 4
Thread: I need solution for this program
- 01-11-2011, 12:56 PM #1
Member
- Join Date
- Oct 2010
- Posts
- 3
- Rep Power
- 0
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...
- 01-11-2011, 01:29 PM #2
Moderator
- Join Date
- Apr 2009
- Posts
- 10,438
- Rep Power
- 16
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.
- 01-11-2011, 01:35 PM #3
Member
- Join Date
- Oct 2010
- Posts
- 3
- Rep Power
- 0
Is there any other way i can call both method() using object of main class without reference super() in class B.
- 01-11-2011, 01:53 PM #4
Moderator
- Join Date
- Apr 2009
- Posts
- 10,438
- Rep Power
- 16
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
-
Comments on my FPS solution
By trader5050 in forum New To JavaReplies: 1Last Post: 11-17-2010, 04:51 PM -
Probably a simple solution
By Collinryans in forum New To JavaReplies: 6Last Post: 06-27-2010, 03:36 AM -
Please I need the solution to this
By debobbt in forum New To JavaReplies: 4Last Post: 12-18-2009, 04:34 AM -
solution for my project
By shkelqa in forum AWT / SwingReplies: 4Last Post: 05-28-2008, 10:31 PM -
Please need solution
By prithvi in forum New To JavaReplies: 4Last Post: 04-22-2008, 01:27 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks