I am making a cricket tournament management system. I has a class named Player
and two child classes Batsman
and Bowler
. The Player
class has following data members:
private String name;
private int ID;
private int age;
private int height;
now Batsman class has Batsman specific members and Bowler class has some Bowler specific members.
I have an abstract addRecord
method in Player class which is implemented in both Batsman and Player class. I want the to use a common file for both child classes in such a way that ID is not duplicated in the file.
And then I can retrieve only Batsman's or only Bowler's records from file as needed and make an array of Batsman or Bowler objects from them.
Is there a way to use Class.forName() and then created an instance of that class by dynamically at runtime using a string containing the class name.
Please help!