1、static
package staticTest;
public class StaticSub extends StaticSup{
public StaticSub(){
System.out.println("我是子类");
}
static{
System.out.println("我是子类的static");
}
public static void main(String[] args){
new StaticSub();
}
}
package staticTest;
public class StaticSup {
public StaticSup(){
System.out.println("我是父类");
}
static{
System.out.println("我是父类的static");
}
}
运行结果
我是父类的static
我是子类的static
我是父类
我是子类
2、string和StringBuffer
package String;
public class StringTest {
String str=new String("hello");
StringBuffer buf=new StringBuffer("hello buffer");
public static void main(String[] args){
StringTest st=new StringTest();
st.change(st.str);
st.change2(st.buf);
System.out.println(st.str);
System.out.println(st.buf);
}
public void change(String str){
str="NewHello";
System.out.println(str);
}
public void change2(StringBuffer buf){
buf.append(" newBuffer");
}
}
运行结果
NewHello
hello
hello buffer newBuffer
3、运行时异常