22sp 041 Cs - Lab2
22sp 041 Cs - Lab2
#02
Object Oriented Programming
Experiment evaluated by
Instructor Name:
Signature:
Task 1
import java.util.*;
}
}
Task 2:
import java.util.*;
}
}
public class Average {
double average;
Task 3:
Data members
1 - Name
2 - Age
3 - Phone number
4 - Address
5 - Salary
It also has a method named 'printSalary' which prints the salary of the
members.
Two classes 'Employee' and 'Manager' inherits the 'Member' class. The
'Employee' and 'Manager' classes have data members 'specialization' and
'department' respectively. Now, assign name, age, phone number, address
and salary to an employee and a manager by making an object of both of
these classes and print the same.
import java.util.*;
// manager
System.out.print("----Manager---");
System.out.println("Name:" + manager.name);
System.out.println("Address:" + manager.Address);
System.out.println("Age:" + manager.age);
System.out.println("Phone Number:" + manager.Phonenumber);
System.out.println("Specialization:" + manager.specialization);
System.out.println("Salary:" + manager.Salary);
// Employee
System.out.print("----Employee---");
System.out.println("Name:" + employee.name);
System.out.println("Address:" + employee.Address);
System.out.println("Age:" + employee.age);
System.out.println("Phone Number:" + employee.Phonenumber);
System.out.println("Specialization:" + employee.department);
System.out.println("Salary:" + employee.Salary);
}
}
public class Member {
String name, Address, Phonenumber;
int age, Salary;
}
Task 4:
Create a class to print an integer and a character with two methods having
the same name but different sequence of the integer and the character
parameters.
For example, if the parameters of the first method are of the form (int n, char
c), then that of the second method will be of the form (char c, int n).
import java.util.*;
}
}
public class Task4 {
int n;
char x;
}
}
}
Task 5:
Suppose a class 'A' has a static method to print "Parent". Its subclass 'B' also
has a static method with the same name to print "Child". Now call this method
by the objects of the two classes. Also, call this method by an object of the
parent class refering to the child class i.e. A obj = new B()
import java.util.*;
}
}
Task 6:
import java.util.*;
}
}
public class A extends Marks {
int a, b, c;
@Override
public double getPercentage() {
return ((a + b + c) / 3.0);
}
}
@Override
public double getPercentage() {
return ((a + b + c + d) / 4.0);
}