????E????д??????壺??????д??????final???????
????F????д??????????????????????????У???????д????
?????????????????private???????????????????????????
public class Test {
public static void main (String[] args) {
//Animal h = new Horse();
Horse h = new Horse();
h.eat();
}
}
class Animal {
private void eat(){
System.out.println ("Animal is eating.");
}
}
class Horse extends Animal{
public void eat(){
System.out.println ("Horse is eating.");
}
}
??????δ?????????????????????????Υ???????????????????????????????Animal???eat()???????????У????Horse???е? eat()???????????μ????????????д?????????????????????Horse?????μ??????????ú?????????????????????????????
????main()???????????????
????Animal h = new Horse();
????//Horse h = new Horse();
????h.eat();
?????????????????????Horse???eat()??????public?????????????e??????μ?????????????????????????????????????????
??????????????
????????????????????????????????????????????????????????????????????????????????????????????????????????????????д??????????????????????????
????1????????????????????????
public class Test {
static void method(byte b){
System.out.println ("method:byte");
}
static void method(short s){
System.out.println ("method:short");
}
static void method(int i){
System.out.println ("method:int");
}
static void method(float f){
System.out.println ("method:float");
}
static void method(double d){
System.out.println ("method:double");
}
public static void main (String[] args) {
method((byte)1);
method('c');
method(1);
method(1L);
method(1.1);
method(1.1f);
}
}
????????????
????method:byte
????method:int
????method:int
????method:float
????method:double
????method:float
???????????????????????????????????????????????????????????????????????????????????????????????????long?????????????????? float?????????????????????????????????????????????????????????????????????С?????????????????????????????????е????????
????char???????????????????????????????????????int??????short?????char??16λ???
????2??????????????
????A??????????????????????б??
?????????????????????????????????????棬???????????????????????????????
????B????????????????????????
????????????????????????????????????????
????C????????????????????????η???
?????????д?????????????????
????D?????????????????????μ??????????????
?????????д?????????????????
????E?????????????????л?????????????б??????
????3???????????ò?????????????
class Animal {}
class Horse extends Animal{}
public class Test {
static void method(Animal a){
System.out.println ("Animal is called.");
}
static void method(Horse h){
System.out.println ("Horse is called.");
}
public static void main (String[] args) {
Animal a = new Animal();
Horse h = new Horse();
Animal ah = new Horse();
method(a);
method(h);
method(ah);
}
}
?????????????
????Animal is called.
????Horse is called.
????Animal is called.
????????????????κ?????????????????????????“Horse is called.”?????????????????????????????????????????????????????????????????????????????????????汾???????????
????4?????????д?????????С??
????????????ū???????????????????????????д?????????????????????????
class Animal {
public void eat(){
System.out.println ("Animal is eating.");
}
}
class Horse extends Animal{
public void eat(){
System.out.println ("Horse is eating.");
}
public void eat(String food){
System.out.println ("Horse is eating " + food);
}
}
public class Test {
public static void main (String[] args) {
Animal a = new Animal();
Horse h = new Horse();
Animal ah = new Horse();
a.eat();
h.eat();
h.eat("apple");
ah.eat();
//a.eat("apple");
//ah.eat("apple");
}
}
??????????????????????????????????????????????
???????????a.eat(); ???????????????ж???????????????????????Animal???eat()???????????Animal is eating.
???????????h.eat(); ?????????????????????????????????Horse???eat()???????????Horse is eating.
????????????h.eat("apple"); ?????Horse???????eat()???????????????Horse???eat(String food)???????????Horse is eating apple
????????????ah.eat(); ?????????????????????????????Horse is eating.
????????????a.eat("apple"); ????????Animal???????eat(String food)???????????????????
????????????ah.eat("apple"); ?????????????????????????????????????????????????????????Animal???????eat(String food)???????????????????
????С????£?????????????????????汾??????????????????д?汾????????á?
???????????????????д????????????????????
??????????
???????????????????????????й?????????????????????????????????????????????????????????????丸????????????????????? Object??????????????????????????new????????????????????????????á?
????1?????????????
????A??????????????κη??????η???????private???????java????к????????????????????????????????????
????B??????????????????????????????????ù????????????????????????sun?????淶???????й???????????????д???
????C?????????????з????????
??????????????з????????????????
????public class Test {
????int Test(){
????return 1;
????}
????}
????????????????????????e??????????????int Test()???????κ??????????????????????????????????????????????????????????????????????
????D????????????д??????????????????????????????????????????????????
?????????????????д?????????????????
????class Test {
????}
???????????Test.class?????????javap Test???????????
????D:"JavaCode"bin>javap Test
????Compiled from "Test.java"
????class Test extends java.lang.Object{
????Test();
????}
?????????????????????????????????
????E???????????????????????????????????????????????ε?????????
????F??????????????У??????????????????this()???????????????????super()?????????this()????????super()??????????????С??????????????????????????????????????????????
????G??????????????????????????????????????super()???????????????????????super()??ε??á?
????H?????????й???????
?????????????????????д???????
????1??????????????????????????????????????
????A??????????????“????”?????????????
????????????£???????????????
????class Father{
????static void print(){
????System.out.println ( " in father   method " );
????}
????}
????class Child extends Father{
????void print(){
????System.out.println ( " in child method " );
????}
????}
????static????????÷?????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????塣
????B?????????????“????”???????????
????????????????????????????????????????Child???print??????????static???η???????????????????????????????????????????????????????????
????class Father{
????static void print(){
????System.out.println ( " in father   method " );
????}
????}
????class Child extends Father{
????static void print(){
????System.out.println ( " in child method " );
????}
????}
????class Test{
????public static void main (String[] args) {
????Father f = new Child();
????f.print();
????}
????}
?????????????in father method
?????????????????????????????????
???????????????????????ò??????????????????????????????μ??
?????????????????????????????????????????
?????????????????????????????
????2???????????????????????????????
?????????????????????????д???????????java????к?????????????
??????java.util.Arrays???????????binarySearch??????
??????????????????????????????????????“sun??SL275?γ??????????????????????????????????У???????????????????????……”
??????????????????????????????????????????????????
??????????????????????????????????????????????????????????????????????????????????