package com.hspedu.encap; //测试类 public class test { public static void main(String[] args) { Sub s = new Sub(); System.out.println(s.count); s.display(); Base b = s; System.out.println(b == s); System.out.println(b.count); b.display(); } } class Base { //父类 int count = 10; public void display() { System.out.println(this.count); } } class Sub extends Base{ int count = 20; public void display() { System.out.println(this.count); } }
标签:count,display,练习,多态,System,println,public,out From: https://www.cnblogs.com/shuqiqi/p/17026108.html