I am trying to create an array of different objects and call class methods for individual objects.
class A
{
int ID,
String name,
public int getID()
{
return ID;
}
public void setID(int id
{
ID = id;
}
}
class B extends A
{
string name;
public string getName()
{
return name;
}
public void setName(string n)
{
name = n;
}
}
class Implement
{
public static void main(string[] args)
{
A[] a1 = new A[2];
a1[0] = new B();
a1[1] = new B();
a1[0].setID(123);
a1[0].setName("John"); //Error
}
}
I am not able to access the B class method. Can any one help me understand why it is not allowing me to access and how to achieve this... Appreciate your help.. Thanks