Java Course

class A {
public void print() {
System.out.println("A");
}
}
class B extends A {
public void print() {
System.out.println("B");
}
public static void main(String[ ] args) {

A object = new B();
B b = (B) object;
b.print();//B
object.print();//B

A object1 = new A();
A c = (A) object1;
c.print();//A
object1.print();//A


((A)object1).print();//A
((A)object).print();//B
((B)object).print();//B


A object2 = new B();
A d = (B)object2;
object2.print();//B
d.print();//B


}
}



Dodaj komentarz






Dodaj

© 2013-2024 PRV.pl
Strona została stworzona kreatorem stron w serwisie PRV.pl