package test;
/*abstract class first{
private String name;
//public abstract boolean Test(String name) {}
//上面这条语句是错误的,抽象方法没有实现,故不应有花括号;或者可以把abstract修饰符去掉
public abstract boolean Test(String name);
}*/
/*public class first{
void doSomething () {
//private String s = ;这条语句private修饰符无效,可以用final修饰
String s = ;
int l = s.length();
}
}*/
/*abstract class Something {
// private abstract String doSomething ();这条语句错误,抽象方法的类型只能设置一个可见性修饰符,一个公共的或受保护的
abstract String doSomething ();
}
*/
/*public class first {
public int addOne(final int x) {
//return ++x;//最终的局部变量不能被分配。它必须空白和不使用复合赋值
return x+1;
}
}*/
/*public class first {
public static void main(String[] args) {
Other o = new Other();
new first().addOne(o);
//System.out.println(o.i);
}
public void addOne(final Other o) {
o.i++;
}
}
class Other {
public int i;
}*/
/* class Something {
int i;
public void doSomething() {
System.out.println(i = + i);
}
} */
/* class Something{
final int i; //错误,final变量i没有初始化
public void doSomething() {
System.out.println(i = + i);
}
}*/
/*public class first {
public static void main(String[] args) {
first s = new first();
System.out.println(s.doSomething() returns + doSomething()); //错误,不能调用非静态方法doSomething
}
public String doSomething() {
return Do something ...;
}
}*/
interface A{
int x = 0;
}
class B{
int x =1;
}
class first extends B implements A {//main函数所在的类应定义为public类型的
public void pX(){
System.out.println(A.x); //这里调用哪个x的值是不明确的,应该为A.x或new B().x;
}
public static void main(String[] args) {
new first().pX();
}
}
该贴由koei转至本版2014-5-2 16:21:57