oop msc

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 6

1. Which of the following is not OOPS concept in Java?

a) Inheritance
b) Encapsulation
c) Polymorphism
d) Compilation
2. 2. Which of the following is a type of polymorphism in Java?
a) Compile time polymorphism
b) Execution time polymorphism
c) Multiple polymorphism
d) Multilevel polymorphism
3. When does method overloading is determined?
a) At run time
b) At compile time
c) At coding time
d) At execution time
4. When Overloading does not occur?
a) More than one method with same name but different method signature and different
number or type of parameters
b) More than one method with same name, same signature but different number of signature
c) More than one method with same name, same signature, same number of parameters but
different type
d) More than one method with same name, same number of parameters and type but
different signature
5. Which concept of Java is a way of converting real world objects in terms of class?
a) Polymorphism
b) Encapsulation
c) Abstraction
d) Inheritance
6. Which concept of Java is achieved by combining methods and attribute into a class?
a) Encapsulation
b) Inheritance
c) Polymorphism
d) Abstraction
7. What is it called if an object has its own lifecycle and there is no owner?
a) Aggregation
b) Composition
c) Encapsulation
d) Association
8. What is it called where child object gets killed if parent object is killed?
a) Aggregation
b) Composition
c) Encapsulation
d) Association
9. What is it called where object has its own lifecycle and child object cannot belong to another
parent object?
a) Aggregation
b) Composition
c) Encapsulation
d) Association
10. Method overriding is combination of inheritance and polymorphism?
a) True
b) false

1. What is encapsulation in Java?


a) The process of combining data and methods into a single unit
b) The process of hiding data and methods within a class
c) The process of creating multiple instances of a class
d) The process of reusing code from existing classes

2. What is inheritance in Java?


a) The process of creating multiple instances of a class
b) The process of hiding data and methods within a class
c) The process of reusing code from existing classes
d) The process of combining data and methods into a single unit

3. What is the difference between method overloading and method overriding in Java?
a) Method overloading occurs within the same class, while method overriding occurs between different
classes.
b) Method overloading involves creating multiple methods with the same name but different parameters,
while method overriding involves providing a different implementation for an inherited method.
c) Method overloading is a compile-time polymorphism concept, while method overriding is a runtime
polymorphism concept.
d) All of the above.

4. What is polymorphism in Java?


a) The ability of a class to inherit properties and behaviors from another class
b) The process of hiding data and methods within a class
c) The process of creating multiple instances of a class
d) The ability of an object to take on many forms

5. What are abstract classes in Java?


a) Classes that cannot be instantiated
b) Classes that can be used as blueprints for creating objects
c) Classes that only contain abstract methods
d) All of the above

6. What is the purpose of the "super" keyword in Java?


a) To refer to the current object
b) To invoke the superclass constructor or methods
c) To create multiple instances of a class
d) To hide data and methods within a class

7. What is the difference between a class and an object in Java?


a) A class is a blueprint for creating objects, while an object is an instance of a class.
b) A class is a single entity, while an object is a collection of entities.
c) A class contains data and methods, while an object only contains data.
d) A class cannot be instantiated, while an object can be created and used.

8. What is the purpose of the "this" keyword in Java?


a) To refer to the superclass
b) To create multiple instances of a class
c) To hide data and methods within a class
d) To refer to the current object

9. What is method overriding in Java?


a) Creating multiple methods with the same name but different parameters within the same class.
b) Providing a different implementation for an inherited method in a subclass.
c) Hiding data and methods within a class.
d) Allowing a class to inherit properties and behaviors from another class.

10. What is the purpose of the "final" keyword in Java?


a) To prevent the inheritance of a class
b) To prevent overriding of a method
c) To prevent modification of a variable's value
d) All of the above

11. What is the purpose of the "abstract" keyword in Java?


a) To prevent the inheritance of a class
b) To prevent overriding of a method
c) To create an instance of a class
d) To declare an abstract class or method

12. What is the difference between static and instance variables in Java?
a) Static variables are associated with the class itself, while instance variables are associated with an
instance of a class.
b) Static variables are shared among all instances of a class, while instance variables have separate values
for each instance.
c) Static variables can be accessed without creating an object, while instance variables require an object
reference.
d) All of the above.

13. What is the concept of data hiding in Java?


a) Encapsulating data within a class and providing controlled access through methods
b) Making data accessible to all classes in the program
c) Storing data in a central repository accessible to multiple classes
d) Restricting access to data within a specific package

1. Which loop construct in Java is best suited when the number of iterations is known?
a) for loop
b) while loop
c) do-while loop
d) break statement

2. What is the purpose of the continue statement in a loop?


a) To exit the loop immediately
b) To skip the current iteration and move to the next iteration
c) To terminate the program
d) To execute a specific block of code

3. Which loop construct in Java is best suited when the number of iterations is unknown?
a) for loop
b) while loop
c) do-while loop
d) none

4. What is the key difference between a while loop and a do-while loop in Java?
a) The syntax used to define the loop
b) The number of iterations performed
c) The condition check timing
d) The ability to use the break statement

5. Which loop construct guarantees that the loop body is executed at least once?
a) for loop
b) while loop
c) do-while loop
d) continue statement

6. What is an infinite loop?


a) A loop that executes only once
b) A loop that never terminates naturally
c) A loop that contains an unreachable code block
d) A loop that uses the continue statement

7. Which statement is used to exit a loop prematurely?


a) return statement
b) continue statement
c) break statement
d) exit statement

8. Which loop construct is best suited for iterating over an array or a collection?
a) for loop
b) while loop
c) do-while loop
d) continue statement

9. Which type of loop is best known for its boolean condition that controls entry to the loop?
A. do-while loop
B. for (traditional)
C. for-each
D. while

10. Which type of loop is best known for using an index or counter?
A. do-while loop
B. for (traditional)
C. for-each
D. while

11. Which of the following can loop through an array without referring to the elements by index?
A. do-while loop
B. for (traditional)
C. for-each
D. while

12. What is the output of the following code snippet?


int i = 0;
for(i = 0 ; i < 5; i++){
}
System.out.println(i);
A. 5
B. 0
C. 4
D. Compilation Error

13. What is the output of the following program?


public class Test{

public static void main(String []args){


int i = 0;
for(i = 0; i < 10; i++){
break;
}
System.out.println(i);
}
}
A. 1
B. 0
C. 10
D. 9

14. What is the output of the following program?


public class Test{

public static void main(String []args){


int i = 0;
for(i = 0; i < 10; i++){
continue;
}
System.out.println(i);
}
}
A. 10
B. 0
C. Compilation error
D. 9

15. What is the output of the following program?


public class Test{

public static void main(String []args){


for(int i = 0; i < 10; i++){
if(i % 2 == 0){
continue;
}
System.out.println(i);
}
}
}
A. Program will print all even numbers between 0 to 10
B. The program will print all odd numbers between 0 to 10
C. Program gives a compilation error
D. None of the above

You might also like