Would you like to react to this message? Create an account in a few clicks or log in to continue.

Polymorphism Ѻ

Go down

  Polymorphism Ѻ Empty Polymorphism Ѻ

ตั้งหัวข้อ  Admin Wed May 21, 2008 12:53 pm

a1 aa=new c1();
1. Constructor ͧ c1
2. Method ͧ a1
Very Happy c1 override method ͧ a1 ͧ c1




public class ConExtends {

public static void main(String[] args) {
a1 aa=new c1(); // ¡ Constructor ͧ c1
aa.a1(); // ¡ method ͧ a1
// aa.b1(); // ¡ method ͧ b1 Error ѡ b1


b1 bb1=new c1(); // ¡ Constructor ͧ c1
bb1.a1(); // ¡ method ͧ a1
bb1.b1(); // ¡ method ͧ b1 Error ѡ b1

c1 cc=new c1(); // ¡ Constructor ͧ c1
cc.a1(); // ¡ method ͧ a1
cc.b1(); // ¡ method ͧ b1 Error ѡ b1


}

}

class a1{
a1(){
System.out.println("A1 Constructor");
}

void a1(){
System.out.println("A1 Method");
}

}

class b1 extends a1{
public b1() {
System.out.println("B1 Constructor");
}

/* // Commant ǹ͡
void a1(){
System.out.println("B1 Method");
}
*/
void b1(){
System.out.println("B1 Method");
}
}

class c1 extends b1{
public c1() {
System.out.println("C1 Constructor");
}

/* void a1(){
System.out.println("C1 Method");
}
*/


}


šѹ
B1 Constructor
C1 Constructor
A1 Method
B1 Method
A1 Constructor
B1 Constructor
C1 Constructor
A1 Method

B1 Method
Admin
Admin
Admin

จำนวนข้อความ : 112
Registration date : 18/05/2008

http://chawban.chocoforum.com

ขึ้นไปข้างบน Go down

ขึ้นไปข้างบน


 
Permissions in this forum:
คุณไม่สามารถพิมพ์ตอบ