以下程序的运行结果是______ abstract class class1{abstract void method1();}class class2 extends class1{public void method1(){ System.out.println("子类");}}public class MainClass{public static void main(String args[]){class1 ac=new class2();ac.method1();}}
举一反三
- 以下语句能顺利通过编译: abstract class class1 { } public class mainClass { public static void main(String args[]) { class1 cs1=new class1(); } } 。()
- abstract class BaseClass { public virtual void MethodA() { } public virtual void MethodB() { } } class Class1: BaseClass { public void MethodA(string arg){ } public override void MethodB(){ } } class Class2: Class1 { new public void MethodB(){ } } class MainClass { public static void Main(string[] args) { Class2 o = new Class2(); Console.WriteLine(o.MethodA()); } } 请问,o.MethodA调用的是 A: BaseClass.MethodA B: Class2.MethodA C: Class1.MethodA D: 都不是
- 对于下面代码,正确的Java源程序文件名是( )。 class A { void method1() { System.out.println("Method1 in class A"); } } public class B { void method2() { System.out.println("Method2 in class B"); } public static void main(String[] args) { System.out.println("main() inclass B"); } }
- 以下程序的编译和运行结果为? abstract class Base{ abstract public void myfunc(); public void another(){ System.out.println("Another method"); } } public class Abs extends Base{ public static void main(String argv[]){ Abs a = new Abs(); a.amethod(); } public void myfunc(){ System.out.println("My Func"); } public void amethod(){ myfunc(); } }
- 请阅读下面的程序,写出运行结果,如果编译失败,写明失败原因。 abstract class Animal{ public final abstract void eat(); } class Cat extends Animal{ public void eat(){ System.out.println("cat...fish"); } } class CatDemo{ public static void main(String[] args){ Animal a = new Cat(); a.eat(); } }