关于以下程序,其编译和运行结果为()classBase{publicBase(){System.out.print('B');}}publicclassTestDemoextendsBase{intm=1;publicTestDemo(){System.out.println('A');}publicstaticvoidmain(Stringargs[]){TestDemot=newTestDemo();}}
举一反三
- 对于一下程序,其运行结果为</p></p>classBase{</p></p>publicBase(){</p></p>System.out.print("C");</p></p>}</p></p>}</p></p>classBase2extendsBase{</p></p>publicBase2(){</p></p>System.out.print("B");</p></p>}</p></p>}</p></p>publicclassTestDemoextendsBase2{</p></p>intm=1;</p></p>publicTestDemo(){</p></p>System.out.println("A");</p></p>}</p></p>publicstaticvoidmain(Stringargs[]){</p></p>TestDemot=newTestDemo();</p></p>}</p></p>}</p></p>
- 下面程序的输出结果是:</p></p>classMyclass{</p></p>staticintmember;</p></p>}</p></p>publicclassTest{</p></p>publicstaticvoidmain(Stringargs[]){</p></p>MyclassA=newMyclass();</p></p>MyclassB=newMyclass();</p></p>Myclass.member=1;</p></p>A.member=2;</p></p>B.member=3;</p></p>System.out.println('member='+Myclass.member);</p></p>}</p></p>}</p></p>
- 已知</p></p><p><p> import java.io.*;</p></p><p><p>class Person{</p></p><p><p>public static void print(){System.out.print("Person");}</p></p><p><p>}</p></p><p><p> class Employee extends Person{</p></p><p><p> public void print(){</p></p><p><p> System.out.print("Employee");}</p></p><p><p>}</p></p><p><p>class Manager extends Employee{</p></p><p><p> public void print(){</p></p><p><p> System.out.print("Manager");}</p></p><p><p>}</p></p><p><p>public class Test{</p></p><p><p> public static void main(String[] args){</p></p><p><p> Manager man = new Manager();</p></p><p><p> Employee emp1 = new Employee();</p></p><p><p> Employee emp2 = (Employee)man;</p></p><p><p> Person person = (Person)man;</p></p><p><p> emp2.print();</p></p><p><p> System.out.print("#");</p></p><p><p> person.print();}</p></p><p><p>}</p></p><p><p>对于以上代码,其输出结果是</p></p>
- import java.io.*;</p></p> class Person{</p></p> public void print(){System.out.print("Person ");}</p></p> public void printMyGender(String s){</p></p> this.print();</p></p> System.out.print(s+" ");</p></p> }</p></p> }</p></p> class Gender{</p></p> String type="gender";</p></p> public void print(Person p){p.printMyGender(type);}</p></p> }</p></p> class Female extends Gender{</p></p> public Female(){</p></p> type="female";</p></p> }</p></p> }</p></p> class Male extends Gender{</p></p> public Male(){</p></p> type="male";</p></p> }</p></p> }</p></p> class Employee extends Person{</p></p> public void print(){</p></p> System.out.print("Employee ");}</p></p> }</p></p> class Manager extends Employee{</p></p> public void print(){</p></p> System.out.print("Manager ");}</p></p> }</p></p> public class Test{</p></p> public static void main(String[] args){</p></p> Manager man = new Manager();</p></p> Employee em = new Employee();</p></p> Gender gender1 = new Male();</p></p> Gender gender2 = new Female();</p></p> gender1.print(man);</p></p> gender2.print(em);</p></p> }</p></p> }</p></p> 对于以上代码,其运行结果是</p></p>
- 根据程序运行结果,完成如下程序。</p></p><p><p>main()</p></p><p><p>{ int x=1,a=0,b=0;</p></p><p><p>switch(x){</p></p><p><p>case 0: b++;</p></p><p><p>case 1: ____;</p></p><p><p>case 2: a++;b++;</p></p><p><p>}</p></p><p><p>printf(“a=%d,b=%d ”,a,b);</p></p><p><p>}</p></p><p>