[go: up one dir, main page]

0% found this document useful (0 votes)
5 views4 pages

List No 3

Uu

Uploaded by

rtxtr92
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)
5 views4 pages

List No 3

Uu

Uploaded by

rtxtr92
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/ 4

Object-Oriented Programming Basics in Java - Task List

1. Introduction to Object-Oriented Programming (OOP)


Theory: Object-Oriented Programming (OOP) is a paradigm that uses 'objects' (instances of
classes) to represent real-world entities, making code modular and reusable.

Reference: https://www.geeksforgeeks.org/object-oriented-programming-oops-concept-
in-java/

Task: Write a paragraph summarizing the four main OOP principles: Encapsulation,
Abstraction, Inheritance, and Polymorphism.

2. Defining a Class
Theory: A class in Java is a blueprint for creating objects, defining attributes (fields) and
behaviors (methods).

Reference: https://www.w3schools.com/java/java_classes.asp

Task: Create a `Person` class with fields for `name` and `age` in a separate `.java` file.

3. Creating Objects
Theory: An object is an instance of a class, created using the `new` keyword. Each object has
its own set of attributes.

Reference: https://docs.oracle.com/javase/tutorial/java/javaOO/objectcreation.html

Task: Instantiate two `Person` objects with different names and ages in a main method.

4. Class Fields and Instance Variables


Theory: Fields or instance variables store the attributes of each object and are defined
within a class.

Reference: https://www.geeksforgeeks.org/fields-in-java/
Task: Add `height` and `weight` fields to the `Person` class and set their values in the main
method.

5. Methods
Theory: Methods define the behaviors of a class and allow objects to interact with their
fields and each other.

Reference: https://www.w3schools.com/java/java_methods.asp

Task: Add a `printDetails` method in the `Person` class that prints the name and age of a
person.

6. Constructors
Theory: Constructors initialize new objects, having the same name as the class and can be
parameterized.

Reference: https://www.javatpoint.com/constructor

Task: Add a parameterized constructor to `Person` to initialize `name` and `age` when
creating a new `Person`.

7. Default Constructors
Theory: If no constructor is provided, Java supplies a default constructor that initializes
objects with default values.

Reference: https://www.geeksforgeeks.org/default-constructors-java/

Task: Remove the parameterized constructor in `Person`, add a default constructor, and
observe default values for `name` and `age`.

8. Getters and Setters


Theory: Getters and setters allow access to private fields while maintaining encapsulation.

Reference: https://www.javatpoint.com/getter-and-setter-in-java
Task: Make `name` and `age` private and add `getName`, `setName`, `getAge`, and `setAge`
methods.

9. Method Overloading
Theory: Method overloading allows multiple methods with the same name but different
parameters, increasing flexibility.

Reference: https://www.javatpoint.com/method-overloading-in-java

Task: Overload `printDetails` to print either just the name or both name and age based on
parameter signatures.

10. The `this` Keyword


Theory: `this` refers to the current instance of the class, commonly used to disambiguate
field names from parameters.

Reference: https://www.w3schools.com/java/ref_keyword_this.asp

Task: Modify the `Person` constructor to use `this` when setting field values.

11. Static Fields and Methods


Theory: Static fields and methods belong to the class rather than individual objects and are
shared among all instances.

Reference: https://www.geeksforgeeks.org/static-keyword-in-java/

Task: Add a static `counter` field in `Person` to count the number of `Person` objects created
and a static method to retrieve this count.

12. Method Return Types


Theory: Methods in Java can return values of different types or `void` if no value is returned.

Reference: https://www.w3schools.com/java/java_methods.asp
Task: Add a method to `Person` that returns a full description string (name, age, height,
weight).

13. Class Constants


Theory: Constants are fields with fixed values, declared with `static final`. They are often
named in uppercase.

Reference: https://www.geeksforgeeks.org/constants-in-java/

Task: Add a `static final int` constant for `MAX_AGE` in `Person` and use it to validate `age`.

14. Encapsulation and Access Modifiers


Theory: Access modifiers (e.g., `public`, `private`) control the visibility of class members.
Encapsulation protects fields.

Reference: https://www.javatpoint.com/encapsulation

Task: Make `name` and `age` private and modify `printDetails` to print `Person` details only
if criteria are met.

15. Final Challenge: Building a Simple Application


Theory: Putting everything together, students can create a structure with multiple
interconnected classes.

Reference: https://www.geeksforgeeks.org/structure-of-a-java-program/

Task: Create an `Employee` class with fields like `id`, `department`, and `salary`. Write
methods to calculate annual salary, print employee details, and compare salaries.

You might also like