(7-1)以下程序的运行结果是( )。
class A{
A(){
System.out.print(10);
}
}
public class Demo extends A {
public static void main(String[] args) {
new A();
new Demo();
}
}
class A{
A(){
System.out.print(10);
}
}
public class Demo extends A {
public static void main(String[] args) {
new A();
new Demo();
}
}
举一反三
- 下列程序运行结果是( ) public class Demo { public static void main(String[] args) { Demo demo = new Demo(); demo.show(new Car() { public void run() { System.out.println("demo run"); } }); } public void show(Car c) { c.run(); } }abstract class Car { public void run() { System.out.println("car run..."); } }
- 定义类Block和类Demo,运行Demo的输出结果是。 class Block{ {//代码1 System.out.print("1"); } static{//代码2 System.out.print("2"); } {//代码3 System.out.print("3"); } public Block() {//代码4 System.out.print("4"); } static void show() {//代码5 System.out.print("5"); } static {//代码6 System.out.print("6"); } } //定义测试类Demo public class Demo { public static void main(String[] args) { new Block().show(); new Block() } }
- {下面程序编译运行的结果是( )class Demo <;T>; {void setData(T a){System.out.print(a);};}public class Demo2015 {public static void main(String[]a){Demo<;String>; d = new Demo<;String>;();d.setData("a");d.setData(1);}}} A: a B: 1 C: a1 D: 编译错误
- 下列程序的运行结果是( )class Demo{private String name;Demo(String name){this.name = name;}private static void show(){System.out.println(name)}public static void main(String[] args){Demo d = new Demo(“lisa”);d.show();}}
- 下列程序运行结果是 public class Demo { public static void main(String[] args) { Object obj=new Father(){ public void show(){ System.out.println("helloworld"); } }; obj.show(); } } class Father{ public void show(){ System.out.println("hello father"); } }