Results 1 to 4 of 4
- 05-31-2011, 07:51 AM #1
Member
- Join Date
- May 2011
- Location
- Bengaluru
- Posts
- 14
- Rep Power
- 0
How to invoke method present in abstract class?
Hellooo every one.
I am new to this forum. plz help me,
i want to invoke method[ m1() ] from abstract class [ Test1 ] by creating object for Test2 class, where i ll be overriding the m1() method in Test2 class. I WANT OUTPUT : "hi" :-)
here is the program:
abstract class Test1
{
public void m1()
{
System.out.println("hi");
}
public abstract void m2();
}
class Test2 extends Test1
{
public void m1()
{
System.out.println("hello");
}
public void m2()
{
System.out.println("how are u");
}
}
class Test
{
public static void main(String args[])
{
Test2 t1=new Test2();
t1.m1();
}
}
- 05-31-2011, 08:09 AM #2
You can't.
I would say you have a design flaw. Either the m1 method in the abstract class should also by abstract, thus the concrete class provides the implementation. Or the m1 method in the abstract class is a non-abstract method and then your concrete class should not override the method.
- 05-31-2011, 11:08 AM #3
Java Is A Funny Language... Really!.gif)
Click on * and add to member reputation, if you find their advices/solutions effective.
- 06-01-2011, 07:13 AM #4
Member
- Join Date
- May 2011
- Location
- Bengaluru
- Posts
- 14
- Rep Power
- 0
Similar Threads
-
abstract method-abstract class
By durgaprasad1407 in forum New To JavaReplies: 1Last Post: 04-29-2011, 06:58 PM -
Class is not abstract and does not override abstract method run(com.
By rgeurts in forum New To JavaReplies: 4Last Post: 04-14-2011, 11:42 AM -
Not abstract and doesn't override abstract method keyReleased
By cc11rocks in forum AWT / SwingReplies: 4Last Post: 02-19-2011, 04:32 AM -
Problems adding new method to an extending abstract class
By harukia in forum New To JavaReplies: 1Last Post: 12-17-2010, 09:24 AM -
Difference between Abstract class having only abstract method and a Interface class
By Santoshbk in forum New To JavaReplies: 6Last Post: 02-11-2009, 10:51 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks