In this program i have input name and code in super class and print it, it also print in sub class Manager
I created the object for super class to input name and code, and another object to input Manager's Data, but in the output the Name is showing null and code is 0, why is this happening??
class Employee{
private int code;
private String name;
protected String input(){
int l=0;
byte[] b=new byte[255];
String S;
try{
l=System.in.read(b,0,255);
}
catch (Exception r){}
S=new String (b,0,l-2);
return S;
}
protected void get(){
System.out.print ("Name: ");
name=input();
System.out.print ("Code: ");
code=Integer.parseInt(input());
}
protected void show(){
System.out.println("Name: " + name);
System.out.println("Code: " + code);
}
}
class Manager extends Employee{ // Manager Profile
private int salary;
private String education,experience;
protected void getdata(){
System.out.print ("Salary (in Digits): ");
salary=Integer.parseInt(super.input());
System.out.print ("Experience (in Letters): ");
experience=super.input();
System.out.print ("Education (in Letters): ");
education=super.input();
}
protected void showdata(){
super.show();
System.out.println("Salary(PKR): " + salary + " PKR");
System.out.println("Education: " + education);
System.out.println("Experience: " + experience );
}
}
class EmployeeeMain{
public static void main(String args[]){
Employee employee = new Employee();
employee.get();
Manager manager = new Manager();
System.out.println ("x-----------------------x\n\nManager's Profile\n");
manager.showdata();
}
}
See the output:
Name: abc
Code: 43
----------------------
Enter Manager's Data
----------------------
Salary (in Digits): 232
Experience (in Letters): asdasd
Education (in Letters): adsasd
x-----------------------x
Manager's Profile
Name: null
Code: 0
Salary(PKR): 232 PKR
Education: adsasd
Experience: asdasd