Object Oriented Programming
CSE · Quiz · Fall 24
Section 64-H
Read the questions as text
Read off the PDF by AI, so it may have mistakes. The PDF is the original.
Daffodil International University
Department of Computer Science & Engineering
Fall 2024
Quiz 1
Course Title: OOP
Course Code: CSE221
Time: 40 minutes
Marks: 15
Answer all the questions:
1. Define Class and Object with appropriate example. [3]
2. Write down detail objects of "University" and find their inter-connection. [4]
3. Write down the UML (Unified Modeling Language) representation of "University" class. [2]
4. Correct the errors (if any) from the following code given below and find the output also. [6]
[Hint: Underline the places where error occurs]
public class NewClass {
Double maximum = 100;
static int var = 75;
public static void main(String[] args) {
int a = 30; b = 10;
system.out.print(a/b);
NewClass obj = New Class();
System.out.print(obj.maximum);
System.out.print(var);
sum();
}
public static void sum() {
NewClass obj = new NewClass();
System.out.print(obj.maximum);
System.in.print(var);
}
}
Daffodil International University
Class Test-1, Fall 2024
CSE 221: Object Oriented Programming
Total Marks: 15
Time: 40 mints
1. Multiple Choice Questions (MCQ) (Each question carries 1 mark) [3 marks].
i. Which of the following concepts is related to the idea of one object behaving differently in different contexts?
a. Inheritance
b. Abstraction
c. Encapsulation
d. Polymorphism
ii. Which of these is NOT a primitive data type in Java?
a. Boolean
b. float
c. String
d. char
iii. Which keyword is used in Java to prevent a method from being overridden in a subclass?
a. static
b. final
c. private
d. public
2. Short Answer Questions (Each question carries 1.5 marks) [3 marks].
a. Explain the concept of polymorphism in Object-Oriented Programming.
b. What is the significance of the static keyword in Java?
3. Consider the following Java code, identify any errors, and provide corrections. Additionally, explain the cause of the errors and why they occurred. [3 marks].
1 - class Example {
2 - int instanceVar = 10;
3 - static int staticVar = 20;
4 -
5 - public void display() {
6 - int instancVar = 30;
7 - System.out.println(instancVar);
8 - System.out.println(instanceVar);
9 - System.out.println(staticVar);
10 - }
11 - public void anotherMethod() {
12 - System.out.println(instanceVar);
13 - }
14 - }
4. Write a Java program that defines a class Rectangle with instance variables for length and width. Create a method to calculate and return the area of the rectangle. Then, demonstrate the usage of this class by creating an object and printing its area. Also draw the basic UML of this program. [6 marks]
Instructions: You must take input from the user, add error handling to ensure the length and width values are positive.
Daffodil International University
Class Test-1, Fall 2024
CSE 221: Object Oriented Programming
Total Marks: 15
Time: 40 mints
1. Multiple Choice Questions (MCQ) (Each question carries 1 mark) [3 marks].
i. What is an instance variable in Java?
a. A variable that is shared by all instances of a class
b. A variable declared inside a method
c. A variable that belongs to an instance of a class
d. A variable declared with the final keyword
ii. Which of the following access modifiers provides the widest scope?
a. Private
b. Default
c. Protected
d. Public
iii. Which of the following statements is true about polymorphism in OOP?
a. It allows objects of different classes to respond to the same method call in different ways
b. It is the process of hiding implementation details
c. It allows one class to inherit properties from another class
d. It only works in non-OOP languages
2. Short Answer Questions (Each question carries 1.5 marks) [3 marks].
a. Explain the concept of encapsulation in Object-Oriented Programming.
b. What is the significance of the static keyword in Java?
3. Consider the following Java code and identify the errors [3 marks].
1 - class Example {
2 - int instanceVar = 10;
3 - static int staticVar = 20;
4 -
5 - public void display() {
6 - int instancVar = 30;
7 - System.out.println(instancVar);
8 - System.out.println(instanceVar);
9 - System.out.println(staticVar);
10 - }
11 - public void anotherMethod() {
12 - System.out.println(instanceVar);
13 - }
14 - }
Instructions: Identify and correct the error in the above code and explain why the error occurred.
4. Write a Java program that defines a class Box with instance variables for height, width, and depth. Create a method to calculate and return the volume of the box. Finally, demonstrate the usage of this class by creating an object and printing its volume. Also draw the basic UML of this program. [6 marks]
Instructions: You must take input from the user, add comments in your code to explain the use of instance variables and methods.
Daffodil International University
Department of Computer Science and Engineering (CSE)
Course Name: Object-oriented programming (OOP)
Course Code: CSE 221
Quiz 01
20 Minutes
SL | Question | Marks
1 | • Explain the concept of a class and an object in Object-Oriented Programming (OOP). Provide a simple example in a programming language of your choice to demonstrate the relationship between a class and an object.
• Convert this UML to java Code and Display height, width and location of a Square
[Figure: UML diagram with classes Lines and Square] | 3+4
2 | Find output:
1.
void myshow();
void main() {
myshow();
myshow();
myshow();
}
void myshow() {
static int k=20;
printf("%d",k);
k++;
}
2.
void main() {
int a=14;
while(a<20){
a++;
if(a>=16 && a<=18)
continue;
printf("%d",a);
}
} | 4+4
Quiz-1
CSE 221
Object Oriented Programming
Time: 50 minutes
Date: 12/9/24
Section: 64-H
1. Write down the differences between property and methods. [3]
2. Imagine an online bookstore that calculates the total price of items in different ways based on customer needs. Sometimes the customer buys a single book, and sometimes they buy multiple books at once. The bookstore has to handle both situations using an overloaded method.
Write down code for the given scenario, and also make an UML Diagram for the code. [7]
3. How many modifiers in java? Write down all the type of the modifiers. [3]
4. Why class is called a blueprint? [2]