[java]代码库
public class ParentClass {
public String str1 = "Parent1";
public String str2 = "";
public ParentClass(){
str2="Parent2";
}
public void func(){
System.out.println("ParentClass.func");
}
public String getStr2() {
return str2;
}
}
public class ChildClass extends ParentClass{
public String str1 = "Child1";
public String str2 = "";
public ChildClass(){
str2="Child2";
}
public void func(){
System.out.println("ChildClass.func");
}
public String getStr2() {
return str2;
}
}
public class Test
public static void main(String[] args) {
ParentClass childCls = new ChildClass();
System.out.println(childCls.str1);
System.out.println(childCls.str2);
System.out.println(childCls.getStr2());
childCls.func();
}
}//源代码片段来自云代码http://yuncode.net
中级程序员
by: 东城 发表于:2016-06-04 11:42:13 顶(0) | 踩(0) 回复
回复评论