给出下列【代码】注释标注的代码的输出结果。class Tom {int weight = 10;void Tom(){weight = 18;}}public class E {public static void main(String args[]) {Tom cat = new Tom();System.out.println(cat.weight); //【代码】}}
举一反三
- 下列 A 类中【代码 1】~【代码 4】哪个是错误的? class Tom { private int x = 120; protected int y = 20; int z = 11; private void f() { x = 200; System.out.println(x); } void g() { x = 200; System.out.println(x); } } public class A { public static void main(String args[]) { Tom tom = new Tom(); tom.x = 22; //【代码 1】 tom.y = 33; //【代码 2】 tom.z = 55; //【代码 3】 tom.g(); //【代码 4】 } }
- 对于下列Tom类,哪个叙述是正确的 public class Test { public static void main(String args[]){ Tom cat1 = new Tom(); Tom cat2 = new Tom(100); } } class Tom { void Tom{ System.out.print("hello"); } Tom(int n){ System.out.print(n); } }
- 给出下列代码的输出结果:public class E{public static void main(String args[]){System.out.println((int)'a');}}
- 给出下列【代码】注释标注的代码的输出结果。________ public class E { public static void main(String args[]){ int [] a ={1,2,3,4,5,6}; System.out.println(a.length+"hello"+a[5]); //【代码】 } }
- 中国大学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”) ; } }