Write a Java program to print employee information (Name, ID, Department) using the Java Method

  • Estimate Completion Time
    not found 30 minutes
  • Difficulty Level:

Solution

public class Employee {
String empname;
int empid;
String department;

public void printInfo() 
{
	System.out.println("Employee Name: " + empname);
	System.out.println("Employee ID: " + empid);
	System.out.println("Employee Department: " + department);
}

public static void main(String[] args) 
{
Employee emp1 = new Employee ();
		emp1.empname = "John";
		emp1.empid = 54;
		emp1.department = "Management";
		emp1.printInfo();
}
}
Output
Employee Name: John
Employee ID: 54
Employee Department: Management

Explanation

  • Create a simple Java class “Employee” with three properties “empname”, “empid” and “department”.
  • A method “printInfo” is created which displays the employee’s information.
  • In the “main” method, an instance “emp1” of “Employee” class is created which sets the value to its properties and calls the method “printInfo” to print the details.
QA Ads Banner

Proleed Academy

Proleed serves / offers professionally designed IT training courses
globally.

Copyright © 2023 - Proleed Academy | All Rights Reserved.