子類對象可以賦值給父類對象;
子類包含的成員方法和成員變量 要比 父類的多;
子類包含父類的成員方法和成員變量;
對於類對象的強制轉換,也就是說,必須先將子類定義的對象賦給父類定義的對象之后才能用子類強制轉換 賦給 新的子類對象
class AA{
AA(){
System.out.println("a");
}
void a1() {
System.out.println("a1");
}
}
class BB extends AA{
BB(){
System.out.println("b");
}
void b1() {
System.out.println("a1");
}
}
public class q {
public static void main(String[] args) {
BB b = new BB();
AA a = new AA();
a=b;
BB c = (BB)a;
}
}
上面運行時正確的,如果子類定義的對象不賦給父類定義的對象的話,編譯運行就會出現錯誤;
定義的對象沒有相互聯系起來,所以不能類強制轉換。
package mytest;
import java.io.IOException;
class AA{
AA(){
System.out.println("a");
}
void a1() {
System.out.println("a1");
}
}
class BB extends AA{
BB(){
System.out.println("b");
}
void b1() {
System.out.println("a1");
}
}
public class q {
public static void main(String[] args) {
BB b = new BB();
AA a = new AA();
// a=b;
BB c = (BB)a;
}
}
aException in thread "main"
b
a
java.lang.ClassCastException: mytest.AA cannot be cast to mytest.BB
at mytest.q.main(q.java:31)
來源:http://www.cnblogs.com/xiaobo-Linux/

父類對象和子類對象引用同一個對象;
父類對象和子類對象所引用的空間內存是相同的;
子類對象可以賦值給父類對象;
