[go: up one dir, main page]

0% found this document useful (0 votes)
6 views2 pages

Worksheet One F

The document is a worksheet focused on Object-Oriented Programming (OOP) principles in Java, consisting of theory and coding questions. It covers key concepts such as encapsulation, inheritance, polymorphism, and includes practical coding exercises to implement these principles. The worksheet aims to enhance understanding and application of OOP in Java programming.

Uploaded by

fikadufaye16
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views2 pages

Worksheet One F

The document is a worksheet focused on Object-Oriented Programming (OOP) principles in Java, consisting of theory and coding questions. It covers key concepts such as encapsulation, inheritance, polymorphism, and includes practical coding exercises to implement these principles. The worksheet aims to enhance understanding and application of OOP in Java programming.

Uploaded by

fikadufaye16
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Worksheet: OOP Principles in Java Programming

Part 1: Theory Questions (10 Questions)

1. What is Object-Oriented Programming (OOP)? How does it differ from procedural


programming?
2. List and briefly explain the four principles of Object-Oriented Programming.
3. Define and explain the term class in Java. How is it different from an object?
4. What is encapsulation? How can you achieve encapsulation in Java?
5. Explain the concept of inheritance. How does it promote code reusability in Java?
6. What is polymorphism in Java? Provide a real-world analogy to explain it.
7. Differentiate between method overloading and method overriding in Java.
8. What is an abstract class in Java? How does it differ from an interface?
9. Explain the use of the super keyword in Java. Provide an example where it is necessary.
10. What is the purpose of the final keyword in Java? How does it affect classes, methods, and
variables?

Part 2: Coding Questions (10 Questions)

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.

You might also like