猿问

抽象类的问题?

public abstract class Shape{}

public class Point extends Shape{
    public Point(double x,double y){
        this.x=x;
        this.y=y
    }
}

现在是这样:

Shape s = new Point(10,10);

如何理解这个实例?

黑山头山大王
浏览 1541回答 3
3回答

凉风5

只要看到抽象类的引用,引用的一定是其子类的实例,这里shape是抽象类,引用的是子类Point的实例对象

慕的地8582982

UDRHWMWSBXBEVJMIGBRUQNDMVSVZOYAXYQLADGQLIDBRUEOQZPZCYBEAHWPQQCKOROBQTXLVRUKNEVKMXZWAXFXGHQJMVVJPSPSWSNDMJYPLJSRAWSVMIFBSCKZDLCYIYTJNYNJGWTPLUKALQECZRSLIQQPPTJHUPNUUOVPYGAAXXOIBIURMVIWGRLIDGWNYNAKHZJQWXRLDQYVJQCWGLLLDEBPJISZJUJGGXRVZWBUOJZTUIPMQDUNURORVSPDOCMVTIBMNPVJXIQBMLMTMPYXAHKGWDNNZJNGJCZSIPRTLVBFYPEVODNDGJCTKPUHTZQOUEEHGDQHKJDBDULPTTHNTKGWGWTJERWXTWGJAJDGLHHKXBDXDYIEGJWWTGWSZRKGQEGKUKWAHZROCQCQGXHBJFCPSOVBOYGVYHKOIYFEPZSYCZNBOKDASWJWYPBFSRGGVZFZWZJFFLFDIWOSOOXXXHLYYYRRAHMMWKMPHGVFJBZMJFLUOXOCBDDGWNDBVVROYZHNQUHBJJSGMZBEZUERHHQBBQJDTXDRAFPESVOXYOOBUXLQDNAARVKBBOQGXDYVZZYYJPIBEBOBKOKPUFGCFOZIYGUZZTDCCMBVWMSYISDWAZGGDPTKNBLOEKKLBUBOLFOEUFTGEYSIRXAXXYEBUBIMXDDEKFZKYOELYFVXTIWSSIQZZMSEKIWFPNEUOCYPWWMPTCSCYXATGZRAJRAALEPCMVSCSFTZICCQAJMCXYKADWZGJLOCOICGWPPCLWZHNNKGHBFOYOKWAEQYRHTWGOORKTXXJPAUDACQTNMFOFFXFCCBZPDMCCQMHXAWLUXHVBXTKMCXTJSCNIRHKGOXNKTDYHYGWZVLOYOYNRBQBQZPS

心有猛虎_细嗅蔷薇

实例化对象的过程就是调用默认构造函数的过程。如果自定义构造函数,系统就不会默认生成。
随时随地看视频慕课网APP

相关分类

Java
我要回答