1、java7中 int类型、枚举类型、字符串类型都可以作 switch 的参数类型,但是浮点型不可以
2、一个以 .java 为后缀的源文件,只能有一个与文件名相同的 public 类,可以有其他非public的类
3、final可以用来声明属性、方法、类,用于表示属性的不可变性、方法的不可覆盖性、类的不可继承性
4、值传递:是指在调用函数时将实际参数复制一份传递到函数中,这样在函数中如果对参数进行修改,将不会影响到实际参数
引用传递:是指在调用函数时将实际参数的地址直接传递到函数中,那么在函数中对参数所进行的修改,将影响到实际参数
5、在JAVA中,假设A有构造方法A(int a),则在类A的其他构造方法中调用该构造方法和语句格式应该为 this(x)
6、函数中的变量不初始化无法使用(编译时报错),类中的成员变量默认初始化为0或null
public class Main {
public static void main(String[] args) {
int a;
System.out.println(a); // 此处编译报错
Q q = new Q();
System.out.println(q.val + " " + q.str); // 0 null
}
}
class Q{
int val;
String str;
}
7、 在基本 JAVA 类型中,如果不明确指定,整数型的默认是 int 类型,带小数的默认是 double 类型
8、static关键词修饰的变量或方法可以通过类名直接调用,而非静态的变量或方法无法通过类名直接调用
9、方法通常储存在进程中的方法区
10、
public class Test{
public static void main(String args[]){
System.out.println(100%3); // 1
System.out.println(100%3.0); // 1.0
}
}
关于 % 两边都是整数,余数是整数;有一边是浮点数,余数是浮点数(商都是整数)
11、
class Test {
public static void hello() {
System.out.println("hello");
}
}
public class MyApplication {
public static void main(String[] args) {
Test test=null;
test.hello();
}
}
可以编译通过,但是运行时报错
12、this( ) 和 super( ) 不能出现在同一个构造方法中,this( ) 和 super( ) 不能出现在静态环境中
13、最终类:final class A ,不可以被继承
最终方法:final void fun() {} ,不可以被重写
最终类中可以没有最终方法
14、int 类型的范围是 [ -2^ 31,2^ 31 - 1 ]