This example uses the following key features in java programing.
Key words
  • "this" key word
  • while loop creating stretchable (infinite) with an exit condition controlled in the caller routine.
  • || operator
  • calling a static method.

import java.io.*;
//import java.util.*;
class Test_this extends process_this
{
public static void main(String args[])throws IOException
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println("-->Welcome to Team roster building<--");
int roster_size=0;
while (roster_size < 3){
System.out.println("Number of Player: "+process_this.p_id);
//write do -- while logic till toster is full
System.out.print("Enter the Test_this's name: ");
String name = br.readLine();
System.out.print("Enter the Test_this's ID: ");
String id = br.readLine();
process_this e = new process_this(name, id);
if ((id != "" )||(name !=""))
{
process_this.AddTest_this();
// Display the new information:
roster_size++;
System.out.println("Player added : "+ e.name + " ID " + e.id);
System.out.println("------" + process_this.p_id + "-----------");
}
//else break;
else return ;
} ;
}
}
class process_this
{
public String id;
public String name;
public static int p_id = 0;
public process_this()
{
// this will not be called due to the logic
System.out.println("Blank Constructor evoked");
}
public process_this(String name, String id)
{
this.name = name;
this.id = id;
}
//there is no destructor in java , this is a parallel example to c#
//~Test_this(){ System.out.println("Overloaded destructor evoked");}
public static int AddTest_this()
{
return ++p_id;
}
}