标签:继承
父亲和儿子的继承关系
class Father { private int asset=10000; public int setAsset(int asset) { this.asset=asset; return asset; } public int getAsset() { return asset; } } class Son extends Father { private int asset=5000; public int setAsset(int asset) { this.asset=asset; return asset; } public int getAsset() { return asset; } } class AssetDemo2 { public static void main(String[] args) { Son s=new Son(); Father f=s; System.out.println(s.getAsset()); System.out.println(f.getAsset()); System.out.println("-----------"); //s.setAsset(200); //f.setAsset(300); //System.out.println(s.setAsset(200)); System.out.println(f.setAsset(300)); System.out.println("-----------"); System.out.println(s.getAsset()); System.out.println(f.getAsset()); } }
本文出自 “yehomlab” 博客,请务必保留此出处http://yehom.blog.51cto.com/5159116/1784234
标签:继承
原文地址:http://yehom.blog.51cto.com/5159116/1784234