Please can anyone tell me what is the error in the following piece of code?
Question is Create a class person which has
- A variable ‘name’ which stores the name of the person.
- A constructor that takes a single argument that is used to initialize the name variable
- A method getName() which displays the name.
- A protected method setName() that takes one argument which is used to modify the name variable.
Create a subclass of the above class called student, which contains
- A variable to store PRN of a student
- A variable to store course the student belongs to
- A method, which displays all the details of the student i.e, name, prn and course.
Program :
class Person
{
String name;
Person(String s)
{
name=s;
}
void getName()
{
System.out.println("Name is "+name);
}
void setName(String sa)
{
name=sa;
}
}
class subPerson extends Person
{
//String sa;
int Prn;
String course;
subPerson(String s,int P,String co)
{
name=s;
Prn=P;
course=co;
}
void displayal()
{
System.out.println("Name is ");
System.out.println("PRN is "+Prn);
System.out.println("course is "+course);
}
}
class Inher
{
public static void main(String args[])
{
int area,volumea;
subPerson h1 = new subPerson("Abhishek",20,"MBA");
h1.displayal();
}
}