给定Java代码如下所示,则编译运行后,输出结果是。
class Parent {
public void count() {
System.out.println(10%3);
}
}
public class Child extends Parent{
public void count() {
System.out.println(10/3);
}
public static void main(String args[]) {
Parent p = new Child();
p.count();
}
}
class Parent {
public void count() {
System.out.println(10%3);
}
}
public class Child extends Parent{
public void count() {
System.out.println(10/3);
}
public static void main(String args[]) {
Parent p = new Child();
p.count();
}
}
举一反三
- 给定一个Java程序的代码如下所示,则编译运行后,输出结果是 ( )。 public class Test { int count = 9; public void count() { System.out.println("count=" + count++); } A: blic static void main(String args[]) new Test().count(); new Test().count();}} B: count=9 count=9 C: count=10 count=9 D: count=10 count=10 E: count=9 count=10
- 给定如下一个 Java源文件 Child.java ,编译并运行 Child.java,以下结果正确的是。 class Parent1 { Parent1(String s) { System.out.println(s); } } class Parent2 extends Parent1 { Parent2() { System.out.println("parent2"); } } public class Child extends Parent2 { public static void main(String[] args) { Child child = new Child(); } }
- 中国大学MOOC: 下列代码中构造方法的返回类型是()public class Village { Village () { System .out .println(“hiding in Village”) ; } public static void main( String args [ ]) { Village c =new Village ( ) ;}class Village { public static void main( String args [ ]) { Village c =new Village ( ) ; } Village () { System .out .println(“hiding in Village”) ; } }
- 下列程序的运行结果是()。 public class Test public static void main ( String [ ] args ) int count = 0 for( int i = 1 i < 5 i = 2) for( int j = 1 j< = 10 j = 3) count System .out .print (count ) _
- 下列代码编译和运行的结果是()。 public class A { public void start() { System.out.println("TestA"); } } public class B extends A { public void start() { System.out.println("TestB"); } public static void main(String[] args) { ((A) new B()).start(); } } A: 输出:TestA B: 输出:TestB C: 输出:TestA TestB D: 编译错误