一道菜鸟题程序如下:class A{public void func1(){System.out.println("A func1 is calling");}public void func2(){func1();}}class B extends A{public void func1(){System.out.println("B func1 is calling");}public void func3(){System.out.println("
来源:学生作业帮助网 编辑:作业帮 时间:2024/08/30 05:47:06
一道菜鸟题程序如下:class A{public void func1(){System.out.println("A func1 is calling");}public void func2(){func1();}}class B extends A{public void func1(){System.out.println("B func1 is calling");}public void func3(){System.out.println("
一道菜鸟题
程序如下:
class A
{
public void func1()
{
System.out.println("A func1 is calling");
}
public void func2()
{
func1();
}
}
class B extends A
{
public void func1()
{
System.out.println("B func1 is calling");
}
public void func3()
{
System.out.println("B func3 is calling");
}
}
class C
{
public static void main(String [] args)
{
B b = new B();
callA(b);
A a = b;
callA(new A());
}
public static void callA(A a)
{
if(a instanceof B)
{
B b = (B)a;
b.func1();
b.func2();
b.func3();
}
a.func1();
a.func2();
}
}
程序编译没有问题,运行就出错,我觉得没有错啊,
一道菜鸟题程序如下:class A{public void func1(){System.out.println("A func1 is calling");}public void func2(){func1();}}class B extends A{public void func1(){System.out.println("B func1 is calling");}public void func3(){System.out.println("
建议:
在Class C前面加public
然后javac C.java
然后就可以java C