OopTh Ass 01
OopTh Ass 01
OopTh Ass 01
ASSIGNMENT 01
Marks: 05
Theoretical Assignment
Read Carefully:
• The deadline for this assignment is before or on 06/11/23
WARNING: This is an individual assignment; you must solve it by yourself. Any form of plagiarism
will result in receiving a zero on the assignment.
WARNING: Late submissions will not be accepted. Any assignment submitted after the cutoff
time will receive zero.
• You have to answer and submit in SOFTCOPY as well as HARDCOPY of the given draft. Submit
SOFTCOPY on your LMS and HARDCOPY to your CR (CR will submit all assignments to Faculty on
the submission date). Both Hardcopy and Softcopy are mandatory.
1|Page
CS Department, BUKC 2 Semester 02 (Fall 2023)
CSC-210: OOP Assignment 01
ANSWER# 01:
ENCAPSULATION:
Definition :
Encapsulation is hiding something within the class boundaries with attributes and behaviors.
Importance :
Encapsulation helps in creating self-contained, reusable, and modular code, which is essential for
building robust software.
Example :
(JAVA code)
public class Book {
private String title;
private String author;
private int publicationYear;
INHERITANCE:
Definition :
Inheritance allows one class to use properties of other class. The class that uses the properties called
child class and the inherited class called parent class.
Importance :
It make easier to extend and manage the code
Example :
(JAVA code )
public class ElectronicDevice {
protected String brand;
protected String model;
POLYMORPHISM:
Definition :
Polymorphism easily says a single class or object’s ability to play as many forms. In other words, there
can be more characteristics with one class according to the situation.
CS Department, BUKC 4 Semester 02 (Fall 2023)
CSC-210: OOP Assignment 01
Importance :
Polymorphism enhances flexibility and extensibility, as you can write code that can work with various
objects without knowing their exact types.
Example :
(JAVA code)
interface MusicPlayer {
void play();
}
ABSTRACTION:
Definition :
Abstraction hides unnecessary things and focus on whats is relevant.
Importance :
CS Department, BUKC 5 Semester 02 (Fall 2023)
CSC-210: OOP Assignment 01
Abstraction promotes clarity and reduces complexity, making it easier to design, understand, and
maintain software systems.
Example :
(JAVA code)
public abstract class Shape {
public abstract double calculateArea();
}
@Override
public double calculateArea() {
return Math.PI * radius * radius;
}
}
@Override
public double calculateArea() {
return sideLength * sideLength;
}
}
2. Summarize the concept of the Constructor, and keep the following statement in consideration to
elaborate your answer. Also, write a small program to copy a constructor.
Polynomial p = new Polynomial(new Term(2.0, 2), new Term(3.0, 1), new Term(-1.0, 0));
CS Department, BUKC 6 Semester 02 (Fall 2023)
CSC-210: OOP Assignment 01
The Polynomial class has a constructor that takes a variable number of Term arguments. It uses the
Arrays.asList method to convert the array of terms into a list. It also has a method evaluate that takes
a variable x and returns the value of the expression evaluated at x. The evaluate method iterates
through the list of terms and computes the value of each term using the Math.pow method and adds
it to the result.
Also derive the polynomial equation which the class Polynomial is handling.
****************************
CODE # 02:
package assignment;
import java.util.List;
import java.util.Arrays;
List<Term> list; //
public Polynomial(Term... terms) {// tree dots is the concept of varags which means variable
arguments it binds all of the arguments in a single array
this.list = Arrays.asList(terms); // returns an array of fixed sized and then assigned to list
}
OUTPUT # 02: