[go: up one dir, main page]

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

Assignment 2

The document outlines an assignment for a Java programming course focused on Object-Oriented Programming concepts, specifically inheritance, method overriding, and polymorphism. It includes tasks to create a base class 'Electronics' and subclasses 'Laptop', 'Smartphone', and 'Television', each with specific properties and methods. Additionally, it requires explanations of OOP principles and the differences between composition and aggregation in Java.

Uploaded by

hanzala6319330
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)
4 views2 pages

Assignment 2

The document outlines an assignment for a Java programming course focused on Object-Oriented Programming concepts, specifically inheritance, method overriding, and polymorphism. It includes tasks to create a base class 'Electronics' and subclasses 'Laptop', 'Smartphone', and 'Television', each with specific properties and methods. Additionally, it requires explanations of OOP principles and the differences between composition and aggregation in Java.

Uploaded by

hanzala6319330
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

CSOO 122 – Object Oriented Programming

Name:
Spring 2025
Roll No Issue Date: March 12, 2025,
Assignment - 2 2025

Task No 1:
Write a Java program that demonstrates inheritance, method overriding, and
polymorphism with multiple classes, additional properties, and enhanced functionalities.
Requirements:
1. Base Class - Electronics
• Private Properties:
o String brand
o double price
o String model
o int warrantyYears
• Public Methods:
o Parameterized Constructor → Initializes all properties.
o powerOn() → Displays a generic power-on message (to be overridden).
o displayInfo() → Prints electronic device details.
o applyDiscount(double discountPercentage) → Reduces price accordingly.
o Getters & Setters → Allow controlled access to private properties.

2. Subclass - Laptop (inherits Electronics)


• Private Properties:
o int ramSize
o String processor
o boolean hasDedicatedGPU
• Public Methods:
o Parameterized Constructor → Initializes Laptop-specific properties along with
Electronics properties.
o Overridden Method: powerOn() → Displays a laptop-specific boot-up message.
o batteryBackup() → Calculates estimated battery life.
o upgradeRAM(int additionalRAM) → Increases RAM size.
o enablePerformanceMode() → Checks if a dedicated GPU is available and optimizes
performance.

3. Subclass - Smartphone (inherits Electronics)


• Private Properties:
o int cameraMP
o boolean is5GEnabled
o int batteryCapacity
• Public Methods:
o Parameterized Constructor → Initializes Smartphone-specific properties along with
Electronics properties.
o Overridden Method: powerOn() → Displays a smartphone-specific boot-up message.
o takePicture() → Prints a message about taking a picture.
o check5GSupport() → Prints whether the device supports 5G.
o batteryLife() → Returns estimated battery life based on usage.

4. Subclass - Television (inherits Electronics)


• Private Properties:
o int screenSize
o String resolution
o boolean isSmartTV
• Public Methods:
National University of Modern languages Page 1 of 2
CSOO 122 – Object Oriented Programming
Name:
Spring 2025
Roll No Issue Date: March 12, 2025,
Assignment - 2 2025

o Parameterized Constructor → Initializes Television-specific properties along with


Electronics properties.
o Overridden Method: powerOn() → Displays a TV-specific startup message.
o changeChannel(int channelNumber) → Prints a message indicating a channel change.
o enableStreamingMode() → Checks if the TV is smart and allows streaming services.
o adjustBrightness(int level) → Adjusts the screen brightness accordingly.

Implementation Instructions:
1. Create objects of Laptop, Smartphone, and Television using parameterized constructors with
relevant attributes.
2. Use an array of Electronics references to store the objects and call powerOn() using runtime
polymorphism.
3. Call both overridden and subclass-specific methods to showcase different functionalities.
4. Demonstrate encapsulation by using getters and setters instead of directly accessing private
properties.
5. Implement method interactions, such as applying a discount with applyDiscount(), checking
batteryLife(), and enabling performanceMode().

Task No 2:
Explain the four main pillars of Object-Oriented Programming (OOP): Abstraction,
Encapsulation, Inheritance, and Polymorphism, with examples.

Task No 3:
Differentiate between composition and aggregation in Java with suitable examples. Explain how
these relationships are implemented in code and their significance in object-oriented design.

National University of Modern languages Page 2 of 2

You might also like