1) Create a Class named “Trainer”.
– Have default instance variables String dept, institute
– Have private instance variable int salary
– Assign 10000 as value for salary.
– Create getter method for salary.
– Assign values – “Java”, “Payilagam” to them
– Have instance method training() with void as return data type
– Add a print statement inside training() method
– Have instance named as ‘trainerKumar’ and pass “CSE”, “payilagam” as arguments to it.
– Handle above line with matching Constructor.
2) Create a sub class “SQLTrainer” under “Trainer”.
– Have main method in it.
– Create instance ram for this class
– Handle with proper super class constructor
– Access parent class instance variables
– Call parent class instance method training()
– Access salary using getter method in parent class
program---
package task;
public class Trainer {
String dept; String institute;
private int salary = 10000;
public Trainer(String dept,String institute)
{
this.dept=dept;
this.institute=institute;
}
public static void main(String[] args) {
Trainer trainerkumar = new Trainer("CSE","payilagam");
}
public int getSalary() {
return salary;
}
public void training()
{
System.out.println("department"+" "+dept+" institute"+" "+institute);
}
}
package task;
public class SQLtrainer extends Trainer
{
public SQLtrainer(String dept, String institute) {
super(dept, institute);
// TODO Auto-generated constructor stub
}
public static void main(String[] args)
{
// TODO Auto-generated method stub
SQLtrainer ram = new SQLtrainer("CSE","payilagam");
ram.training();
int salary = ram.getSalary();
System.out.println(salary);
}
}
Top comments (0)