Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Semrush - keyword research tool

Turn ChatGPT, Claude, Gemini, And CoPilot Into Your Personal Assistant, Business Coach, Content Creator, And More

AFFILIATE MARKETING Your all-in-one performance engine Manage affiliates, creators, and customer referrals in one unified platform—turning every partnership into measurable growth
Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

42,709 questions

55,473 answers

573 users

How to create and use a simple employee class in Java

1 Answer

0 votes
// Employee.java

package javaapplication1;

public class Employee {

   String name;
   int age;
   double salary;
	
   // Constructor
   public Employee(String name){
      this.name = name;
   }
   public void employeeAge(int eAge){
      age =  eAge;
   }
   public void employeeSalary(double eSalary){
      salary = eSalary;
   }
   public void printEmployee(){
      System.out.println("Name:"+ name);
      System.out.println("Age:" + age);
      System.out.format("Salary: %.2f\n", salary);   
   }
}
// javaapplication1.java

package javaapplication1;

public class JavaApplication1 {
 
    public static void main(String[] args) {
        
        Employee e1 = new Employee("Dr. Who");
        Employee e2 = new Employee("Axus");

        e1.employeeAge(192);
        e1.employeeSalary(82000);
        e1.printEmployee();

        e2.employeeAge(87);
        e2.employeeSalary(54000);
        e2.printEmployee();
    }
}
 
/*
run:
 
Name:Dr. Who
Age:192
Salary: 82000.00
Name:Axus
Age:87
Salary: 54000.00
 
*/

 



answered Sep 6, 2016 by avibootz

Related questions

1 answer 219 views
1 answer 251 views
1 answer 513 views
1 answer 135 views
1 answer 237 views
237 views asked Jul 8, 2018 by avibootz
...