Monday, June 30, 2014

Inheritance part 1

package InheritancePolymorphism;

public class InheritancePolymorphism {
public void Method1(){
System.out.println("supermethod");

}


}

package InheritancePolymorphism;

public class SubClass1 extends InheritancePolymorphism{

public SubClass1() {
}
public void Method1(){
System.out.println("subclass1");
}
package InheritancePolymorphism;

public class SubClass2 extends InheritancePolymorphism{

public SubClass2() {
}
public void Method1(){
System.out.println("subclass2");
}

}

package InheritancePolymorphism;

import org.junit.Test;




public class Main {
@Test
public void Method1() {
InheritancePolymorphism[] tests={new SubClass1(),new SubClass2()};
for(InheritancePolymorphism test:tests){
test.Method1();
}
}

}

No comments:

Post a Comment