Creating your own Java Class:

ppackage Com.Suryawanshi;

class Employee{
int id;
String name;
int salary;
public void printDetails(){
System.out.println("My id is "+id);
System.out.println("My name is "+name);
}
public int getSalary(){
return salary;
}
}
public class CreatingCustomClass {
public static void main(String[] args) {
Employee Abhay = new Employee();
Abhay.id = 101;
Abhay.name = "'Abhay Suryawanshi'";
Abhay.salary = 15000;
Abhay.printDetails();
System.out.println("My salary is "+Abhay.getSalary());

System.out.println("------------------------------------------");

Employee Sudhir = new Employee();
Sudhir.id = 102;
Sudhir.name = "'Sudhir Abhang'";
Sudhir.salary = 16000;
Sudhir.printDetails();
System.out.println("My salary is "+Sudhir.getSalary());

}
}

OutPut:
My id is 101
My name is 'Abhay Suryawanshi'
My salary is 15000
------------------------------------------
My id is 102
My name is 'Sudhir Abhang'
My salary is 16000

Comments

Popular posts from this blog

Creating code for Rock Paper Scissors:

Practice Set For Basic OOPs Concept: