Worksheet One F
Worksheet One F
11. Write a Java class Student with private fields for name and age,gpa,year, Department .
Include getter and setter methods to access these fields. Demonstrate encapsulation in your
code.
12. Create a base class Animal with a method sound(). Derive two subclasses Dog and Cat, and
override the sound() method to provide specific sounds.
13. Design a class hierarchy for a Shape superclass with subclasses Circle and Rectangle. Include
methods to calculate the area of each shape. Use inheritance in your solution.
14. Write a Java program to demonstrate method overloading. Create a class Calculator with
multiple methods named add() to handle different numbers and types of parameters.
15. Implement a simple program that demonstrates method overriding. Create a parent class
Vehicle with a method move(), and override it in a subclass Car.
16. Write a program that demonstrates polymorphism using an interface Animal. Implement
classes Dog and Cat that provide their own versions of the makeSound() method.
17. Create a program that uses an abstract class Employee with an abstract method
calculateSalary(). Implement subclasses FullTimeEmployee and PartTimeEmployee with specific
salary calculation logic.
18. Write a program to demonstrate the use of the final keyword in Java. Include examples of
final variables, methods, and classes.
19. Design a program that demonstrates the use of constructors in Java. Include a default
constructor, parameterized constructor, and copy constructor for a class Book.
20. Create a Java program that uses hierarchical inheritance. Create a superclass Appliance and
two subclasses WashingMachine and Refrigerator. Include methods unique to each subclass.