java继承过程中方法覆盖问题——“=”左右两边分别为父类和子类类型
摘要:1 package cn.tju.acculation.base; 2 3 public class Extend { 4 5 public static void main(String args[]) { 6 //在方法覆盖中,左右俩边分别为父类和子类的时候,以左边作为调用的入口,右边作为调用的实际调用执行的方法。 7 P t2= new T(); 8 //t2是Parent的对象,t2调用的方法只能是Parent的方法,但是实际调用是调用子类还是父类的方法,是看new谁,new谁就调用谁 9 //只有子类的对象...
阅读全文
java中的this和super关键字
摘要:1 package cn. tju. acculation. keywords; 2 3 4 public class ThisAndSuper { 5 6 public static void main( String[] args ) { 7 Student s1 = new Student( "zhangsan" , 14) ; 8 s1 .print (); 9 10 Student s2 = new Student( "lisi" , 12, "23" );11 ...
阅读全文