Practical 1

  1. Write a program to demonstrate class, constructor, properties and method. Solution

  2. Write a program to demonstrate method overloading. Solution

  3. Create a class Calculate which contains data member num1 and num2 both in integer and methods setCalc() to set the data, calcSum() that calculate the sum of num1 and num2 and display the result, calcMulti() that calculate the multiplication of num1 and num2 and returns the result, calcDifference that calculate the difference between num1 and num2 and display the result. Now, create some instance of Calculate and invoke all the methods. Solution

  4. Create a class Number having instance variable x and y both in integer, default constructor that set the value of x and y to 0, parameterized constructor that sets the value of x and y, method findOdd() that calculates the even no. occurring between x and y and display the result, findEven() that calculates the odd no. occurring between x and y and display the results. Now, create some instance of Number and invoke all the methods. Solution

  5. Create a class Shape that contains instance variable length, breadth and height. Create a default constructor that sets the value of instance variable to zero, constructor with two parameter that will sets the value of length and breadth only and constructor with three parameter that will sets the value of length, breadth and height. After this create calcAreaRectangle() that calculates the area of rectangle, calcVolumeBox() that calculates volume of box and display the result. Now create first object of Shape wihich will have name rectangle and calls constructor with two parameter and calAreaRectangle() method, create second object of Shape that will have name Box which will call constructor with three parameter and calcVolumeBox() method. Solution

  6. Create a class EmployeeDetails having data member empId, empName, empGender, empAddress, and empPosition, constructor to set the details and display method to display the details. Create a subclass SalaryInfo that will inherit EmployeeDetails having own data member salary which will record salary per year, constructor to set the value of salary and method calcTax() that deduct the tax on salary and display the final salary. Tax rate is given as (if salary <= 400000 tax is 1%, salary between 400001 to 800000 tax is 10% and salary > 800000 tax 20%). Now create the object of Salary info and demonstrate the scenario. Solution

  7. Write a program to demonstrate single level, multilevel inheritance. Solution

  8. Write a program to demonstrate use of base keyword. Solution

  9. Write a program to demonstrate method overriding (dynamic polymorphism). Solution

  10. Write a program to demonstrate multiple inheritance using interface. Solution

  11. Write a program to demonstrate abstract class. Solution

  12. Write a program to demonstrate exception handline (try, catch, throw throws). Solution

  13. Write a program to demonstrate interface. Solution

  14. Write a program to demonstrate lamda expression. Solution

Last updated