/*****************TestFinal.java end ***********************/
/*****************TestOverload.java begin ***********************/
public class TestOverload { public void amethod(int i, String s){}
//加入其他方法 //下面哪些方法可以加入到Sample類(lèi)中,并且保證編譯正確呢?
// public void amethod(String s, int i){} (可以) // public int amethod(int i, String s){return 0;} (不可以) // private void amethod(int i, String mystring){} (不可以) // public void Amethod(int i, String s) {} (可以) // abstract void amethod(int i); (不可以) } /** * 抽象類(lèi)Sample (abstract public class Sample) * @author Administrator * */ abstract class Sample{ public static void main( String[] s){}
//加入其他方法 //下面哪些方法可以加入到Sample類(lèi)中,并且保證編譯正確呢?
// abstract public void main(String s, int i); // public final static int main(String[] s){return 0;} // private void main(int i, String mystring){} (可以) // public void main( String s) throws Exception{} (可以)
}
/*****************TestOverload.java end ***********************/
/*****************TestOverride .java begin ***********************/
public class TestOverride {
public TestOverride method()throws RuntimeException{ return null; }
/*****************TestOverride .java end ***********************/
/*****************TestSuper .java begin ***********************/
public class TestSuper {
public static void main(String[] args) { // TODO Auto-generated method stub B b=new B(); b.show(); }
} class A { public int n=10; } class B extends A { public int n=100;
public void show (){ int n=1000; System.out.println(n);//調(diào)用方法內(nèi)部中的屬性 System.out.println(this.n);//調(diào)用本類(lèi)中的屬性 System.out.println(super.n);//調(diào)用父類(lèi)中的屬性
}
}
/*****************TestSuper .java end ***********************/
/*****************TestSuper1 .java begin ***********************/
public class TestSuper1 {
public static void main(String args[]){ Test test=new Test(1); // Test test1=new Test(1); } }