举一反三
- 下列 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”) ; } }
内容
- 0
(7-7)阅读程序,写出程序运行结果。 //写出程序运行结果 class Eye {// 猫的眼睛类 private String color; public Eye(String color) { this.color = color; } } class Cat {// 猫类 private String name; private Eye eye; public Cat(String name, Eye eye) { this.name = name; this.eye = eye; } public boolean equals(Object obj) { Cat cat = (Cat) obj; if (this.name.equals(cat.name) && this.eye == cat.eye) return true; return false; } } public class CatDemo { public static void main(String[] args) { Eye e1=new Eye("蓝色"); Cat tom1=new Cat("Tom",e1); Cat tom2=new Cat("Tom",e1); System.out.println(tom1==tom2); System.out.println(tom1.equals(tom2)); } }
- 1
下列ABCD注释标注的哪行代码有错public class Demo { public static void main(String args[]) { System.out.println("Java"); system.out.println("hello"); System.out.println("你好"); } } A: public class Demo B: public static void main(String args[]) C: system.out.println("ok"); D: System.out.println("您好");
- 2
以下代码的输出结果 ? public class Test1{ static int x = 3; static { ++x; } public static void main(String args[]){ System.out.println(x); } static { x++; } }
- 3
【单选题】下列哪行代码有错误? public class Example{ public static void main(String args[]){ System.out.println("ok"); system.out.println("您好"); } } A. public class Example B. public static void main(String args[]) C. System.out.println("ok"); D. system.out.println("您好");
- 4
说出下列B类中【代码1】,【代码2】的输出结果 class A { public int getNumber(int a) { return a+1; } } class B extends A { public int getNumber (int a) { return a+100; } public static void main (String args[]) { A a =new A(); System.out.println(a.getNumber(10)); //【代码1】 a = new B(); System.out.println(a.getNumber(10)); //【代码2】 } }