I am very new in programming, while learning Java i got into a doubt, my situation is, I am trying to call a implemented method of a class TestingImpl1111 from interface ITesting1111 in a test class by creating a object of a abstract parent class using child class constructor, but i am not able to call the method m1() which was as implemented in class TestingImpl1111 as out put. it always brings the overridden method m1 in class TestingImpl2222
this is my code below :-
package PolymorphismAndAbstraction.Example1.Example2;
interface ITesting1111
{
void m1();
void m2();
void m3();
}
abstract class TestingImpl1111 implements ITesting1111
{
public void m1()
{
System.out.println("testing method from interface in class 1111");
}
}
abstract class TestingImpl2222 extends TestingImpl1111
{
public void m1()
{
System.out.println("testing method m1 from interface in class 2222 which was implemented in class 1111 as well.");
}
public void m2()
{
System.out.println("testing method from interface in class 2222");
}
}
class TestingImpl3333 extends TestingImpl2222
{
public void m2()
{
System.out.println("testing method m2 from interface in class 3333 which was implemented in class 2222 as well.");
}
public void m3()
{
System.out.println("testing method from interface in class 3333");
}
}
public class Test1234
{
public static void main(String[] args)
{
TestingImpl1111 obj = new TestingImpl3333();
((TestingImpl1111)obj).m1();
obj.m1();
((TestingImpl2222)obj).m2();
obj.m2();
obj.m3();
}
}
and below is output i am geting :-
testing method m1 from interface in class 2222 which was implemented in class 1111 as well.
testing method m1 from interface in class 2222 which was implemented in class 1111 as well.
testing method m2 from interface in class 3333 which was implemented in class 2222 as well.
testing method m2 from interface in class 3333 which was implemented in class 2222 as well.
testing method from interface in class 3333
But output i am expecting is :-
testing method m1 from interface in class 2222 which was implemented in class 1111 as well.
testing method from interface in class 1111
testing method m2 from interface in class 3333 which was implemented in class 2222 as well.
testing method from interface in class 2222
testing method from interface in class 3333
Please explain me what I am doing wrong here how do i get my desiered output ??