1.
abstract class Name {
private String name;
public abstract boolean isStupidName(String name) {}
}
答案: 错
2.
public class Something {
void doSomething () {
private String s = "";
int l = s.length();
}
}
答案: 错。
3.
abstract class Something {
private abstract String doSomething ();
}
答案: 错。
4.
public class Something {
public int addOne(final int x) {
return ++x;
}
}
答案: 错。
5.
public class Something {
public static void main(String[] args) {
Other o = new Other();
new Something().addOne(o);
}
public void addOne(final Other o) {
o.i++;
}
}
class Other {
public int i;
}
答案: 正确。
6.
class Something {
int i;
public void doSomething() {
System.out.println("i = "+ i);
}
}
答案: 正确。
7.
class Something {
final int i;
public void doSomething() {
System.out.println("i = "+ i);
}
}
答案: 错。
8.
public class Something {
public static void main(String[] args) {
Something s = new Something();
System.out.println("s.doSomething() returns " + doSomething());
}
public String doSomething() {
return "Do something ...";
}
}
答案: 错。
9.
此处,Something类的文件名叫OtherThing.java
class Something {
private static void main(String[] something_to_do){
System.out.println("Dosomething ...");
}
}
答案: 正确。
10.
interface A{
int x = 0;
}
class B{
int x =1;
}
class C extends B implements A {
public void pX(){
System.out.println(x);
}
public static void main(String[] args) {
new C().pX();
}
}
答案:错误。
11.
interface Playable {
void play();
}
interface Bounceable {
void play();
}
interface Rollable extends Playable, Bounceable {
Ball ball = new Ball("PingPang");
}
class Ball implements Rollable {
private String name;
public String getName() {
return name;
}
public Ball(String name) {
this.name =name;
}
public void play() {
ball = newBall("Football");
System.out.println(ball.getName());
}
}
答案: 错。
|