
package start;
class A { protected void a() //a method in A { System.out.println("Class A"); } }
class B extends A { public B() { super();
}
public void a()
{
super.a();
System.out.println("Class B"); //A's a method overridden in B
}
}
class C extends B {
public void a() //B's a method overridden in C
{
super.a();
System.out.println("Class C");
}
}
public class M {
public static void main(String arg[])
{
//Creating a oblect of C
C oC=new C();
oC.a();
//My Question = How to call A's in main an dont wanna print B an C???
}
}

Hi Friend,
Try this:
class A {
protected void a(){
System.out.println("Class A");
}
}
class B extends A {
public B() {
super();
}
public void a(){
super.a();
System.out.println("Class B");
}
}
class C extends B {
public void a(){
super.a();
System.out.println("Class C");
}
}
public class M {
public static void main(String arg[]){
A a=new A();
a.a();
}
}
Thanks

thks for the ans sir but u change the object creation in main class but i just want ti know that there is any way to call class without creating its object in main class,please give the ans sir
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.