1.java静态方法不能引用在同一个类中的非静态方法和非静态成员变量
public class DoSomething {
public static void main(String[] args) {
// TODO Auto-generated method stub
DoSomething ds = new DoSomething();
//System.out.println("ds.dosomething returns"+ doSomething()); 错误的
System.out.println("ds.dosomething returns :"+ ds.doSomething());
System.out.println(x);
System.out.println("ds.x returns :"+ ds.x);
}
public static int x=1;
public String doSomething(){
return "do something.....";
}
}
2.抽象类方法的实现
abstract class Name{
public abstract boolean isStupidName(String name);
//public abstract boolean isStupidName(String name){} 这样是错误的
}
3.局部变量不能添加任何修饰符
<span style="font-size:18px;">class Something{
void doSomething(){
//private String s = ""; only final 可以修饰局部变量的
String s = "";
int l = s.length();
}
}</span>
4.抽象类方法前不能加private和final修饰符,抽象方法的具体实现细节是为了让子类来实现的,因此不能为private和final
5.被final修饰的变量不可以修改,但如果修饰对象,可以更改对象里的内容,不可以改变对象的引用
6.实例变量有缺省值,但被final修饰的变量没有默认缺省值,必须初始化指定初始值
7.public class的名字必须和文件名相同,其他的类没有必要必须和其文件名相同
8.父类和接口同时存在同名变量时候,指定是父类的还是接口的成员变量
<span style="font-size:18px;">public class C extends B implements A{
public void pX(){
System.out.println(super.x);
System.out.println(A.x);
//System.out.println(x);
}
public static void main(String[] args) {
// TODO Auto-generated method stub
new C().pX();
}
}
interface A{
int x = 0; //默认为public static final
}
class B{
int x = 1;
}</span>