Assignment

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…


This content originally appeared on DEV Community and was authored by hema latha

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);
}

}


This content originally appeared on DEV Community and was authored by hema latha


Print Share Comment Cite Upload Translate Updates
APA

hema latha | Sciencx (2025-01-03T13:42:54+00:00) Assignment. Retrieved from https://www.scien.cx/2025/01/03/assignment/

MLA
" » Assignment." hema latha | Sciencx - Friday January 3, 2025, https://www.scien.cx/2025/01/03/assignment/
HARVARD
hema latha | Sciencx Friday January 3, 2025 » Assignment., viewed ,<https://www.scien.cx/2025/01/03/assignment/>
VANCOUVER
hema latha | Sciencx - » Assignment. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2025/01/03/assignment/
CHICAGO
" » Assignment." hema latha | Sciencx - Accessed . https://www.scien.cx/2025/01/03/assignment/
IEEE
" » Assignment." hema latha | Sciencx [Online]. Available: https://www.scien.cx/2025/01/03/assignment/. [Accessed: ]
rf:citation
» Assignment | hema latha | Sciencx | https://www.scien.cx/2025/01/03/assignment/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.