This section contains carefully selected MCQs and Previous Year Questions with explanations to help students understand concepts and prepare effectively for examinations, interviews, and competitive tests.
Q: 1___________ is mechanism by which one class acquires the properties – data fields and methods of another class.
Option C
Inheritance is a fundamental concept in object-oriented programming (OOP) where one class acquires the properties (data fields) and methods of another class. The class inheriting the properties is called the derived class or subclass or child class, while the class from which it inherits is called the base class or superclass or parent class. Inheritance promotes code reusability.
| OOP’S FEATURE | MEANING |
| Encapsulation | Wrapping data and functions into a single unit (class). Protects data from outside interference. It ensures data security and prevents unauthorized access. |
| Abstraction | Hiding unnecessary implementation details and showing only essential features. It provides simplicity by focusing on what an object does, not how it does it. |
| Inheritance | One class acquires the properties and behaviors of another. It promotes code reusability and establishes relationships. |
| Polymorphism | Ability of the same entity (method/operator) to behave differently based on context. It provides flexibility and reduces code complexity. |
Q: 2What is Encapsulation in Java?
Option C
Encapsulation in Java is one of the fundamental principles of Object-Oriented Programming (OOP). An act of combining data (variables) and the methods that operate on that data into a single unit called a class.
Through encapsulation, the internal details of an object are hidden from the outside world, allowing controlled access via getter and setter methods. This helps maintain data security, ensures better control over the data, and prevents unintended modification.
| CONCEPT | DESCRIPTION | KEY FEATURES |
|---|---|---|
| Encapsulation | The OOP principle of combining data (variables) and methods (functions) into a single unit and restricting direct access to it. |
|
| Class | A blueprint or template from which objects are created. It defines properties (variables) and behaviors (methods). |
|
| Object | An instance of a class that has its own identity, state, and behavior. It occupies memory. |
|
Q: 3Which of the following statements is FALSE?
Option A
In Java, the final keyword can be applied to methods to prevent them from being overridden by a subclass. When a method is declared as final, its implementation cannot be changed through method overriding.
E.g.:
class Parent
{
public final void display()
{
System.out.println("Parent Method");
}
}
class Child extends Parent
{
// Compilation Time Error
public void display()
{
System.out.println("Child Method");
}
}
Q: 4Which mechanism allows a superclass reference to refer to a subclass object?
Option B
In Java, a superclass reference can refer to an object of its subclass. This is an important feature of polymorphism.
E.g.:
class Animal
{
void sound()
{
System.out.println("Animal Sound");
}
}
class Dog extends Animal
{
void sound()
{
System.out.println("Dog Barks");
}
}
class TestExample
{
public static void main(String args[])
{
Animal aObj = new Dog();
aObj.sound();
}
}
OUTPUT
Dog Barks
Here, aObj is a reference of type Animal, but it refers to a Dog object. When aObj.sound() is called, Java determines at runtime which overridden method should be executed.
Since the actual object is a Dog, the Dog version of sound() is executed. This runtime method selection is called Dynamic Binding or Dynamic Method Dispatch.
Q: 5A class which cannot be inherited is called?
Option D
In Object-Oriented Programming (Java), a final class is a class that cannot be extended or inherited by any other class.
When a class is declared using the keyword final, it prevents other classes from inheriting it.
final class A
{
void displayMessage()
{
System.out.println("Suraku Academy");
}
}
class B extends A { } //Error.
Q: 6Which of these keywords is used to prevent content of a variable from being modified in Java?
Option D
In Java, the final keyword is used when we want a variable value to remain unchanged after it has been assigned. Such a variable is commonly treated as a constant.
E.g.:
class Example
{
public static void main(String args[])
{
final int num=22;
System.out.println(num);
//num=33; Compilation Error
}
}
Q: 7A class that exhibits a high degree of primitiveness encapsulates only ______________ operations.
Option B
In object-oriented programming, a class is a blueprint for creating objects and can encapsulate (combine) data (variable) and operations (methods). The degree of primitiveness of a class refers to how basic or elementary its responsibilities are.
Q: 8Which of the following is NOT an object-oriented feature?
Option B
Object-Oriented Programming (OOP) is based on several important features that help in designing reusable, secure, and manageable programs. The major features of OOP are:
| OOP Feature | Purpose |
|---|---|
| Encapsulation | Binds data and its associated functions together in one unit. |
| Inheritance | Acquires properties of another class. |
| Abstraction | Show only essential features and hides unnecessary implementation details. |
| Polymorphism | One entity behaves in multiple (several) forms. |
Q: 9Which of the following is NOT an OOPs concept in Java?
Option C
Java is primarily an object-oriented programming language, and OOP is based on concepts that help organize a program around classes and objects. The four commonly recognized fundamental OOP concepts are encapsulation, inheritance, polymorphism, and abstraction.
Compilation is not an OOP concept. It is the process of converting Java source code into bytecode using the Java compiler (javac).
Q: 10Which of the following declares an abstract method in an abstract Java class?
Option A
The abstract keyword is used to declare an abstract class and abstract methods in Java. In Java, an abstract method is a method that is declared without a method body. It only specifies what the method should do, while the implementation is provided by a subclass.
Syntax:
abstract ReturnType MethodName();
E.g.:
abstract class Shape
{
public abstract void draw();
}
class Circle extends Shape
{
public void draw()
{
System.out.println("Drawing Circle");
}
}
class Example
{
public static void main(String args[])
{
Circle c = new Circle();
c.draw();
}
}
OUTPUT
Drawing Circle
E.g.:
abstract class Calculator
{
public void add(int a, int b)
{
System.out.println("Addition : "+(a+b));
}
}
class AdvancedCalculator extends Calculator
{
}
class Example
{
public static void main(String args[])
{
// Calculator c = new Calculator(); //Not Allowed
AdvancedCalculator obj = new AdvancedCalculator();
obj.add(11,22);
}
}
OUTPUT
Addition : 33
Thank you so much for taking the time to read my Computer Science MCQs section carefully. Your support and interest mean a lot, and I truly appreciate you being part of this journey. Stay connected for more insights and updates! If you'd like to explore more tutorials and insights, check out my YouTube channel.
Don’t forget to subscribe and stay connected for future updates.