This is an example of polymorphism, where a same method in derived classes has been overridden to print something different.
 

 

import java.io.*;
//import java.lang.reflect.*;
public class Test_This {
public static void main(String[] args) throws IOException{
// TODO Auto-generated method stub
System.out.println("------------------");
Team[] tt= { new Team(), new Defense("A"), new Offense("C"), new Mid("E") };
System.out.println("------------------");
try{
for (int i = 0; i < 4; i++)
{System.out.println(" Print " +tt[i].position());}
}//try

catch(NumberFormatException e)
{ System.out.println("data was blank");}

}
}

class Team
{
private String p1 ="Soccer Team Lancer";
public Team() { System.out.println("Default Team constructor");}
public Team(String str) { System.out.println("Team constructor " + str);}
public String position() { System.out.println("Check line up of " + this.getClass().getName()); return p1; }
}
class Defense extends Team
{
private String p1="Defense";
public Defense(String str) {super(str); System.out.println(this.getClass().getName()+ " class gets : " + str); }
public String position() { System.out.println("\tDefense responded"); return p1; }
}
class Offense extends Team
{
private String p1="Offense";
public Offense(String str) {super(str); System.out.println(this.getClass().getName()+ " class gets : " + str); }
public String position() { System.out.println("\tOffense reponded");return p1; }
}
class Mid extends Team
{
private String p1 ="Mid";
public Mid(String str) {super(str); System.out.println(this.getClass().getName()+ " class gets : " + str); }
public String position() { System.out.println("\tMid responded"); return p1; }
}