Monday, February 2, 2015

Java polymorphism for beginners

                             


video by : Jose Vidal




In order to understand the Java polymorphism, try the following.







class Yellow {
int a, b;

Yellow() {
}

Yellow(int i, int j) {
a = i;
b = j;
}

void printY() {
System.out.print(a + b);
}
}

class Brown extends Yellow {
Brown(int i, int j) {
}

void printB() {
System.out.print("Brown");
}
}

class Test {
public static void main(String args[]) {
Yellow ob1 = new Brown(6, 8);
ob1.printB();
}
}

No comments:

Post a Comment

Constructor Chaining