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 ...";
}
}
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();
}
} 作者: 张旺达 时间: 2013-5-27 10:51
有答案不咯~~{:soso_e144:}作者: FantasticPie 时间: 2013-5-27 11:55 本帖最后由 FantasticPie 于 2013-5-27 12:35 编辑
1. 抽象方法是由子类来实现的,因此不能有方法的具体实现。去掉第三行的{};
2. doSomething()这个方法中定义的变量是私有变量,不能加修饰符,所以要去掉String s 前的private要去掉。