EXPERIMENT NO2java
EXPERIMENT NO2java
1) Problem Statement : Create a class called Employee that includes three pieces of
information as instance variables first name, a last name and a monthly salary. Your class
should have a constructor that initializes the three instance variables. Provide a set and a get
method for each instance variable. If the monthly salary is not positive, set it to 0.0. Write a test
application named EmployeeTest that demonstrates class Employee's capabilities. Create two
Employee objects and display each object's yearly salary. Then give each Employee a 10% raise
and display each Employee's yearly salary again.
Program:
class Employeedetails {
String Firstname;
String Last name;
float monsalary;
float yearlysalary;
float increasesalary;
void displaydata() {
System.out.println("Employee's Firstname: " + this.Firstname);
System.out.println("Employee's Last name: " + this.Lastname);
if (this.monsalary < 0) {
this.monsalary = 0;
}
Output :
2) Problem Statement : Write a Java Program to demonstrate the use of static variable,
static block and static method.
Program:
public StaticDemo() {
System.out.println("Constructor is called.");
count++;
}
public static void displayCount() {
System.out.println("Count of objects created: " + count);
}
public static void main(String[] args) {
Output :
Conclusion : Students should able to write java program using class and objects.