package com.caishui.model;
public class TestSon {
public staticvoidmain(String[] args){
Son son=new Son();
son.say();
Parent parent=new Son();//向上转型
parent.say();
Son son1=(Son) parent;//向下转型
son1.say();
Parent parent2=new Parent();if(parent2 instanceof Son){
System.out.println("parent类型是son类型");}else{
System.out.println("parent类型不是son类型");
Son son2=(Son) parent;}}}
package com.caishui.model;
public class Parent {
private String name;
public String getName(){return name;}
public voidsetName(String name){
this.name = name;}
public voidsay(){
System.out.println("普通话");}
public Parent(){super();// TODO Auto-generated constructor stub
System.out.println("构造器");}}
package com.caishui.model;
public class Son extends Parent {
public Son (){super();
System.out.println("========Son构造器=====");}
public voidsay(){
System.out.println("普通话");}}