ITeye博客

JAVA综合基本功(1)

lujinglong · 2011-04-20 18:47 · 编程语言 · Markdown

1.变量定义以字母,下划线,美元符号$开头。 2.if(a){},a变量必须为boolean类型。 example: int i = 1; int j = 2; if(i==1&|j==2){System.out.println("OK");} 以上例子在编译阶段出现错误。 3.接口interface只能实现(implements)不能继承,只有实现了接口中的方法,接口类和实现接口类之间才简历关系。 4.在一个类中,静态语句块不参与main函数中的运算。 example: public class Static{ static { int x = 5;//再以下运算中,没使用过该值. } static int x,y; public static void main(String args){ x--; System.out.println("x="+x); System.out.println("y="+y); System.out.println("-----调用myMethod前后的值--------"); myMethod(); System.out.println("x="+x); System.out.println("y="+y); System.out.println("----计算后的结果--------"); System.out.println(x + y + ++x); } public static void myMethod(){ y = (x++)+(++x); } }

Result:结果 x=-1 y=0 -----调用myMethod前后的值-------- x=1 y=0 ----计算后的结果-------- 3

  1. package, import, class先是包名,然后是导入import,最后才是类的声明。 6.boolean值的默认初始值是false. example: public class Static{

    static boolean Paddy; public static void main(String argv){ System.out.println(Paddy); }

} 输出的结果是:false 7.类的赋值,只能把子类的引用赋给基类变量,不可以把父类的引用指向子类的变量中。

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。