Skip to content
Topic guide · Programming

Object-Oriented Programming (OOP): Classes, Objects and the Four Pillars · অবজেক্ট ওরিয়েন্টেড প্রোগ্রামিং (ওওপি): ক্লাস, অবজেক্ট ও চারটি মূল স্তম্ভ

Object-oriented programming (OOP) builds a program from objects, where each object is an instance of a class that bundles data (attributes) with the functions that work on it (methods). Its four pillars are encapsulation (binding data with methods and hiding the data behind access modifiers), abstraction (showing what an object does, not how), inheritance (a child class reusing a parent class, an "is-a" relation) and polymorphism (one name, many forms). Polymorphism comes in two kinds: compile-time polymorphism through overloading, and run-time polymorphism through overriding, which C++ achieves with virtual functions and Java with ordinary instance methods.

অবজেক্ট ওরিয়েন্টেড প্রোগ্রামিং (ওওপি) অবজেক্ট দিয়ে প্রোগ্রাম তৈরি করে; প্রতিটি অবজেক্ট কোনো ক্লাসের ইনস্ট্যান্স, আর ক্লাস ডেটা (অ্যাট্রিবিউট) ও সেই ডেটার ওপর কাজ করা ফাংশন (মেথড) একসঙ্গে বেঁধে রাখে। এর চারটি মূল স্তম্ভ: এনক্যাপসুলেশন (ডেটা ও মেথড একসঙ্গে বেঁধে অ্যাক্সেস মডিফায়ার দিয়ে ডেটা লুকানো), অ্যাবস্ট্রাকশন (অবজেক্ট কী করে তা দেখানো, কীভাবে করে তা নয়), ইনহেরিট্যান্স (চাইল্ড ক্লাস প্যারেন্ট ক্লাসকে পুনর্ব্যবহার করে, "is-a" সম্পর্ক) ও পলিমরফিজম (এক নাম, বহু রূপ)। পলিমরফিজম দুই ধরনের: ওভারলোডিংয়ের মাধ্যমে কম্পাইল-টাইম পলিমরফিজম এবং ওভাররাইডিংয়ের মাধ্যমে রান-টাইম পলিমরফিজম; সি++ এটি ভার্চুয়াল ফাংশন দিয়ে এবং জাভা সাধারণ ইনস্ট্যান্স মেথড দিয়েই করে।

Asked in past exams
113
Papers
77

1. Procedural vs object-oriented programming

In procedure-oriented programming (POP), as in C, a program is a list of functions that act on data kept separately, often in global variables. Any function can change any data, so as a program grows, bugs spread and code is hard to reuse. Object-oriented programming (OOP) keeps the data and the functions that use it together in one unit, the object, and controls who may touch the data.

Point POP (procedural) OOP
Building block Function (procedure) Object, made from a class
Data and functions Kept separately Bundled together
Data security Data is mostly open (global) Data hidden with private and public access
Design approach Top-down: split the task into functions Bottom-up: model the objects first, then combine them
Reuse Copying code, calling functions Inheritance and composition
Overloading Not supported in C Supported (methods; operators in C++)
Example languages C, Pascal, FORTRAN C++, Java, C#, Python, Smalltalk

C++ and Python are multi-paradigm: they allow both styles. Java is strongly object-oriented, yet not "pure", because int, char and the other primitive types are not objects. Smalltalk is the usual example of a pure object-oriented language. That is why an MCQ asking "Which one is a pure OO language?" with only C++, Java and similar languages in the options keys "None".

Advantages of OOP (a common written question): reuse through inheritance, data security through hiding, easier maintenance because changes stay inside a class, modelling of real-world things, and easier teamwork because classes can be built and tested separately.

2. Class and object

  • A class is a blueprint: a user-defined type that declares data members (attributes) and member functions (methods). A class on its own holds no object's data.
  • An object is an instance of a class, a real thing in memory with its own copy of the data members. Making an object is called instantiation; Java always uses new, while C++ can create an object directly on the stack or with new on the heap.
  • A class therefore contains both data and functions. Exam keys often define a class as a group of objects that share the same attributes and the same behaviour.

C++: one class, two objects.

#include <iostream>
using namespace std;

class Rectangle {
private:
    double width, height;                 // data members (attributes)
public:
    Rectangle(double w, double h) {       // constructor
        width = w;
        height = h;
    }
    double area() { return width * height; }   // member function (method)
};

int main() {
    Rectangle r1(3, 4), r2(5, 2);         // two objects of one class
    cout << r1.area() << " " << r2.area() << endl;   // prints: 12 10
    return 0;
}

In Java the same object is made with Rectangle r1 = new Rectangle(3, 4);. The variable r1 holds a reference to the object, which lives on the heap.

3. The four pillars

Pillar One-line meaning How it is achieved Everyday picture
Encapsulation Bind data with its methods in one unit and hide the data Private fields with public getter and setter methods A capsule: the medicine is sealed inside
Abstraction Show the essential features, hide the implementation Abstract classes and interfaces Driving a car with a steering wheel and pedals, without knowing the engine
Inheritance A new class acquires the members of an existing class ("is-a") extends in Java, : public Base in C++ A Dog is an Animal
Polymorphism One name, many forms Overloading (compile time) and overriding (run time) The word "open" for a door, a file or a bank account

Encapsulation vs abstraction, the most common trap: encapsulation hides the data (with access modifiers), abstraction hides the implementation (behind an interface or abstract class). The two work together: hiding the data is one way to present an abstract view, which is why some keys say encapsulation "ensures abstraction". Global variables break encapsulation, because every function can change them.

class Account {
    private double balance;                       // hidden data
    public double getBalance() { return balance; }
    public void deposit(double amount) {
        if (amount > 0) balance = balance + amount;   // the class guards its own data
    }
}

Some books list more "features of OOP" than the four pillars: class, object, dynamic binding and message passing (objects calling each other's methods). Things that are not OOP features, and appear as wrong options: recursion, exception handling, compilation, iteration, structured goto-free code.

4. Access modifiers

Access modifiers (access specifiers) decide where a member can be used.

C++ has three:

Specifier Same class Derived class Outside code
public Yes Yes Yes
protected Yes Yes No
private Yes No No

Two C++ defaults that MCQs ask: in a class members are private by default (in a struct they are public), and a class that inherits without saying how gets private inheritance (class D : Base); a struct gets public inheritance. The private members of a base class cannot be accessed in a derived class, although they still exist inside the derived object.

Java has four levels:

Modifier Same class Same package Subclass in another package Everywhere
public Yes Yes Yes Yes
protected Yes Yes Yes No
(none: default, package-private) Yes Yes No No
private Yes No No No

Java's protected is wider than C++'s, because it also opens the member to the whole package.

5. Constructors and destructors

A constructor is a special method that runs automatically when an object is created and gives the object its starting values.

  • It has the same name as the class and no return type, not even void.
  • It can be overloaded. Types: default (no parameters), parameterised, and in C++ the copy constructor ClassName(const ClassName& other), which builds a new object as a copy of an existing one.
  • The copy constructor's parameter must be a reference. If it took the object by value, passing the argument would itself need a copy, which would call the copy constructor again, without end. g++ refuses such code: "invalid constructor; you probably meant 'Point (const Point&)'".
  • Constructors are not inherited, and in C++ a constructor cannot be virtual.
  • Java has no copy constructor built in, but you can write one; Java also has no destructor.

A destructor (C++ only) cleans up when the object is destroyed: its name is the class name with a tilde, such as ~Vehicle(); it takes no arguments, has no return type and cannot be overloaded. Java has no destructors: the garbage collector frees objects that nothing refers to. (Java's old finalize() method is deprecated and was never a reliable destructor.)

Worked example 1: the order of constructors and destructors.

#include <iostream>
using namespace std;

class Base {
public:
    Base()  { cout << "Base constructor" << endl; }
    ~Base() { cout << "Base destructor" << endl; }
};

class Derived : public Base {
public:
    Derived()  { cout << "Derived constructor" << endl; }
    ~Derived() { cout << "Derived destructor" << endl; }
};

int main() {
    Derived d;          // object created here
    return 0;           // d goes out of scope here
}
  1. Creating d must first build the Base part inside it, so Base constructor prints first.
  2. Then the Derived part is built: Derived constructor.
  3. When main ends, d is destroyed in the reverse order: Derived destructor, then Base destructor.

Output: Base constructor, Derived constructor, Derived destructor, Base destructor. Rule: constructors run base first (top-down), destructors run derived first (bottom-up). In Java the same holds for constructors: super() runs before the rest of the child's constructor.

6. Polymorphism: overloading vs overriding

Point Overloading Overriding
Kind of polymorphism Compile-time (static) Run-time (dynamic)
Binding Static (early) binding Dynamic (late) binding
Where Usually in one class In a subclass, replacing a parent method
Method name Same Same
Parameter list Must differ (number, type or order) Must be the same
Return type Can differ, but a different return type alone is not enough Same, or a covariant subtype (Java 5+; in C++ only for pointer or reference returns)
Access modifier Any Java: cannot be more restrictive than the parent's (a public method stays public); C++ does not restrict it
Needs inheritance No Yes
Examples add(int, int) and add(double, double); operator overloading in C++ area() redefined in Circle

Static binding means the compiler fixes which function a call goes to; dynamic binding means the choice is made while the program runs, from the actual type of the object. C++ supports operator overloading (Complex operator+(const Complex&)), the usual keyed answer to "Which one is compile-time polymorphism?". Java does not let you overload operators; its only built-in exception is + joining strings.

Worked example 2: what does this Java program print?

class Shape {
    String name = "Shape";
    double area() { return 0; }
    static String kind() { return "shape"; }
}

class Circle extends Shape {
    String name = "Circle";
    double r;
    Circle(double r) { this.r = r; }
    @Override
    double area() { return 3.14 * r * r; }      // overriding (run time)
    static String kind() { return "circle"; }   // hiding, not overriding
}

class Calc {                                    // overloading (compile time)
    int add(int a, int b)           { return a + b; }
    double add(double a, double b)  { return a + b; }
    int add(int a, int b, int c)    { return a + b + c; }
}

public class Main {
    public static void main(String[] args) {
        Shape s = new Circle(1);          // parent reference, child object
        System.out.println(s.area());
        System.out.println(s.kind());
        System.out.println(s.name);
        Calc c = new Calc();
        System.out.println(c.add(2, 3));
        System.out.println(c.add(2.5, 3.5));
        System.out.println(c.add(1, 2, 3));
    }
}
  1. s.area(): area is an overridden instance method, so Java looks at the object (a Circle) at run time: 3.14.
  2. s.kind(): static methods are not overridden, only hidden; the call is fixed at compile time by the reference type (Shape): shape.
  3. s.name: fields are not polymorphic either; the reference type decides: Shape.
  4. The three add calls are matched by the compiler from the argument types: 5, 6.0 and 6.

The same idea in C++ needs virtual. In C++ a call through a base pointer is bound statically unless the function is declared virtual:

#include <iostream>
using namespace std;

class Animal {
public:
    void eat()           { cout << "Animal eats" << endl; }   // not virtual
    virtual void sound() { cout << "Some sound" << endl; }    // virtual
    virtual ~Animal() {}
};

class Dog : public Animal {
public:
    void eat()   { cout << "Dog eats" << endl; }
    void sound() { cout << "Bark" << endl; }                  // overrides
};

int main() {
    Animal* p = new Dog();
    p->eat();      // prints: Animal eats  (static binding)
    p->sound();    // prints: Bark         (dynamic binding)
    delete p;
    return 0;
}

In Java every non-static, non-private, non-final method behaves like a C++ virtual function, so no keyword is needed. A pure virtual function (virtual double area() = 0;) has no body and makes its class abstract in C++. Give a base class a virtual destructor whenever objects are deleted through a base pointer, as above. Without it, delete p is undefined behaviour: nothing is guaranteed (often only the base destructor runs, but no output can be relied on). Compilers usually build dynamic binding with a virtual table (vtable): each class with virtual functions has a table of function addresses, and each object holds a hidden pointer to its class's table.

To call the parent's version of an overridden method from the child: C++ uses the scope resolution operator (Animal::sound();), Java uses super.sound().

7. Abstract classes and interfaces

An abstract class cannot be instantiated; it may mix abstract methods (no body) with ordinary ones, and subclasses fill in the gaps. An interface is a pure contract of what a class can do; a class implements it (so "interfaces are meant to be implemented").

Point Abstract class (Java) Interface (Java)
Keyword to use it extends implements (an interface extends other interfaces)
How many per class Only one (single class inheritance) Many
Methods Abstract and concrete Abstract; since Java 8 also default and static methods (Java 9 adds private)
Fields Any fields Only constants (implicitly public static final)
Constructor Yes (runs when a subclass object is made) No
Member access Any modifier Methods are public by default
Relationship "is-a" (shared base) "can-do" (a capability)
interface Drawable {
    void draw();                                                   // abstract by default
    default void info() { System.out.println("I can be drawn"); }  // Java 8+
}
interface Resizable { void resize(double factor); }

abstract class Shape {
    abstract double area();                                        // no body
    void describe() { System.out.println("Area = " + area()); }    // concrete
}

class Square extends Shape implements Drawable, Resizable {
    double side;
    Square(double side) { this.side = side; }
    double area() { return side * side; }
    public void draw() { System.out.println("Drawing a square"); }
    public void resize(double f) { side = side * f; }
}
// new Square(2).describe() prints "Area = 4.0"; after resize(1.5) it prints "Area = 9.0"

An abstract class can implement interfaces (several at once) without defining their methods; its concrete subclasses then must. C++ has no interface keyword: a class with only pure virtual functions plays that role.

8. Types of inheritance and the diamond problem

Type Shape Java classes C++
Single B inherits A Yes Yes
Multilevel C inherits B, B inherits A Yes Yes
Hierarchical B and C both inherit A Yes Yes
Multiple C inherits A and B No (only through interfaces) Yes
Hybrid A mix, for example hierarchical plus multiple Only through interfaces Yes
In the diamond problem, class D inherits class A twice, once through B and once through C.

The diamond problem. If B and C both inherit A, and D inherits both B and C, then D contains two copies of A, and d.show() is ambiguous: g++ stops with "request for member 'show' is ambiguous". Without the fix, building a D runs A's constructor twice (the output is A B A C D).

Worked example 3: fixing the diamond in C++ with virtual inheritance.

#include <iostream>
using namespace std;

class A { public: A() { cout << "A "; } void show() { cout << "A::show" << endl; } };
class B : virtual public A { public: B() { cout << "B "; } };
class C : virtual public A { public: C() { cout << "C "; } };
class D : public B, public C { public: D() { cout << "D" << endl; } };

int main() {
    D d;          // prints: A B C D
    d.show();     // prints: A::show
    return 0;
}
  1. virtual public A tells the compiler that B and C will share one A.
  2. Building D now builds A once (first, because virtual bases come first), then B, then C, then D: A B C D.
  3. With a single A, d.show() is no longer ambiguous.

Java's answer is to forbid a class from extending two classes (class Z extends X, Y does not compile) and to allow many interfaces instead. If two interfaces give the same default method, the class must override it, or javac reports that the types "are incompatible"; inside the override it can pick one with A.super.hello().

Composition ("has-a") is the alternative to inheritance: a Car has an Engine object as a field. It is the answer to "which feature lets you use an object of one class inside another class?" Has-a comes in two strengths: in composition the part cannot exist without the whole (a House and its Rooms), while in aggregation the part lives on its own (a Department and its Teachers). Both are kinds of association, the general "uses" link between classes.

9. static members, this and super

  • A static member belongs to the class, not to any object: there is one shared copy, reached as ClassName.member. A typical use is counting objects.
  • A static method can be called without an object, so it cannot use this or super and cannot use instance fields or call instance methods directly (javac: "non-static variable this cannot be referenced from a static context"). Static methods are hidden, not overridden. main is static so that the JVM can call it before any object exists.
  • this refers to the current object; it separates a field from a parameter with the same name (this.name = name) and can call another constructor of the same class (this(...)). In C++ this is a pointer, so the field is written this->name.
  • super (Java) refers to the parent part: super(...) calls the parent constructor and must be the first statement of a constructor (the classic rule that exams test; Java 25 relaxed it with flexible constructor bodies); super.method() calls the parent's version of an overridden method. C++ has no super; it names the base class (Base::method()) and calls base constructors in the initialiser list.
class Animal {
    Animal() { System.out.println("Animal()"); }
    String sound() { return "..."; }
}

class Dog extends Animal {
    static int count = 0;            // one copy, shared by all Dog objects
    String name;
    Dog(String name) {
        super();                     // calls Animal(); must be the first statement
        this.name = name;            // this.name is the field, name the parameter
        count++;
        System.out.println("Dog(" + name + ")");
    }
    @Override
    String sound() { return super.sound() + " Woof"; }   // reuse the parent's version
}
// new Dog("Tommy"); new Dog("Bruno");  prints Animal(), Dog(Tommy), Animal(), Dog(Bruno)
// Dog.count is then 2, and a Dog's sound() returns "... Woof"

10. Neighbouring questions and tricky exam cases

Built-in (inbuilt) classes. Every language ships ready-made classes in its library. In Java: Object (the root of every class), String, Math, System, Scanner, Thread, collection classes such as ArrayList and HashMap, and the wrapper classes (Integer, Double, Character …). Turning a primitive into its wrapper object automatically (Integer x = 5;) is autoboxing; the reverse is unboxing. In C++, the standard library gives string, vector, map and the stream classes. (.NET has its own Base Class Library.)

Structure vs class (C++). A struct can hold functions too; the only differences are the defaults: struct members and inheritance are public by default, class ones private.

Friend function (C++). A function declared with friend inside a class is not a member of that class, yet it can read the class's private and protected members. It is called like an ordinary function, without an object and the dot operator, and it is often said to weaken encapsulation. Friendship is neither inherited nor mutual.

The final keyword (Java). On a variable it makes a constant (it can be assigned only once), on a method it stops overriding, and on a class it stops inheritance: String is a final class, so class F extends String fails with "cannot inherit from final String".

Tricky cases:

  1. Private methods cannot be overridden. A private method is not inherited, so a child method with the same name is a brand-new method. If a parent method calls its own private m(), it still runs the parent's version even on a child object (tested: it prints the parent's message). This is why keys mark "private methods are final" as true; a final method also cannot be overridden (javac: "cannot override"). Protected methods are not final.
  2. Static methods are hidden, not overridden (worked example 2), so "can a static method be overridden?" is answered no.
  3. Overloading by return type alone is illegal: int f() and double f() in one class do not compile.
  4. An abstract subclass may re-declare an inherited concrete method as abstract, forcing its own subclasses to implement it. This is legal in Java, and an MCQ keys it as the correct statement.
  5. Java classes cannot do multiple inheritance, but interfaces can: "Which is not a feature of Java OOP? Multiple inheritance" (of classes).
  6. C cannot do inheritance: C has structs but no classes. "Which language does not support inheritance? C."
  7. A constructor is a special method with no return type, invoked automatically when an object is initialised; in Java, "Box obj = new Box();" both declares and creates an object.

Practice · অনুশীলন

  1. What is the difference between compile-time and run-time polymorphism? Give one example of each.
    Answer

    Compile-time (static) polymorphism is resolved by the compiler from the argument list: method or operator overloading, such as add(int, int) and add(double, double). Run-time (dynamic) polymorphism is resolved while the program runs from the actual object type: method overriding, such as Shape s = new Circle(1); s.area() calling Circle's area(). In C++ the overridden function must be declared virtual.

  2. Which members of a base class cannot be accessed directly in a derived class, and what is the default inheritance mode of a C++ class?
    Answer

    Private members (they exist inside the derived object but only the base class's own functions can use them). A C++ class inherits privately by default (class D : Base), while a struct inherits publicly.

  3. Why must a C++ copy constructor take its argument by reference?
    Answer

    Passing an object by value makes a copy, and making a copy calls the copy constructor. If the copy constructor took its argument by value, it would call itself without end, so the compiler rejects it; the correct form is ClassName(const ClassName& other).

  4. Give three differences between an abstract class and an interface in Java.
    Answer

    A class can extend only one abstract class but implement many interfaces; an abstract class can have constructors and ordinary instance fields while an interface has no constructor and only public static final constants; an abstract class can have any mix of abstract and concrete methods with any access, while interface methods are public and abstract unless declared default or static (Java 8+).

  5. How does C++ solve the diamond problem, and how does Java avoid it?
    Answer

    C++ declares the middle classes with virtual inheritance (class B : virtual public A, class C : virtual public A), so the bottom class D contains only one shared A and calls to A's members are no longer ambiguous. Java does not allow a class to extend more than one class; multiple inheritance is possible only through interfaces, and a clash between two default methods must be resolved by overriding.

Asked in past exams · আগের পরীক্ষায় যেভাবে এসেছে

Our past papers have 113 questions on this topic (44 MCQ, 69 written) from 77 exams. Here are 12 of them; each links to its full paper.

  1. The class in C++ contains:

    • a)data only
    • b)function only
    • c)data and function both (correct answer)
    • d)None of the above
    Explanation · ব্যাখ্যা

    Correct answer: (c) data and function both

    A C++ class is a user-defined type whose members are mainly data members (the object's state) and member functions (the operations on that state). Keeping both in one unit, with access control (private, protected, public), is what encapsulation means. For example:

    class Account {
        double balance;                                   // data member
    public:
        void deposit(double amt) { balance += amt; }      // member function
    };
    

    Why the other options are wrong

    • (a) data only: A class is not limited to data; member functions are a core part of it.
    • (b) function only: A class is not limited to functions; it normally holds data members too.
    • (d) None of the above: Wrong because (c) correctly describes what a class contains.

    A particular class may happen to have only data or only functions, but the general answer to what a class contains is both.

    Tip: Class = data members + member functions, wrapped together (encapsulation).

    Source: Classes - cppreference.com

  2. Which of the following does NOT achieve encapsulation?

    • a)Using private access specifier
    • b)Using classes in object-oriented programming
    • c)Using getter and setter methods
    • d)Using global variables (correct answer)
    Explanation · ব্যাখ্যা

    Correct answer: (d) Using global variables

    Encapsulation keeps an object's data together with the methods that work on it, and hides that data so outside code can reach it only through those methods. A global variable does the opposite: it belongs to no object, and any function anywhere in the program can read or change it directly, with no checks. It gives neither bundling nor hiding.

    Why the other options are wrong

    • (a) Using private access specifier: private limits a member to its own class. This is the main tool for data hiding.
    • (b) Using classes in object-oriented programming: a class puts fields and the methods that operate on them into one unit. That is the bundling half of encapsulation.
    • (c) Using getter and setter methods: they are the controlled path to private fields and can validate values (for example, reject a negative age). That is controlled access.

    Tip: encapsulation = bundle + hide + controlled access. Anything that lets every part of the program change data freely breaks it. (Java has no true global variables; public static fields come closest and weaken encapsulation in the same way.)

    Source: What Is an Object? (The Java Tutorials, Oracle)

  3. What is runtime polymorphism and compile time polymorphism? Explain it's with example.

    Model answer on the paper page

  4. Interfaces in Java are meant to be-

    • a)Extended
    • b)Implemented (correct answer)
    • c)Overridden
    • d)Used by creating object
    Explanation · ব্যাখ্যা

    Correct answer: (b) Implemented

    An interface declares a contract (method signatures, constants, and since Java 8 default and static methods). It does nothing on its own until a class writes class C implements I and supplies a body for each abstract method. That is why interfaces are described as meant to be implemented. Oracle's tutorial notes that an interface cannot be instantiated: it can only be implemented by classes or extended by other interfaces.

    Why the other options are wrong

    • (a) Extended: Only another interface can extend an interface, and that just builds a larger contract which still needs a class to implement it. Extension is possible but is not the purpose.
    • (c) Overridden: Methods are overridden; an interface as a whole is not. A class implements the interface's abstract methods.
    • (d) Used by creating object: new I() is a compile error, because an interface cannot be instantiated. You create an object of a class that implements it.

    Tip: class extends class; class implements interface; interface extends interface.

    Source: Defining an Interface / Interfaces - The Java Tutorials (Oracle)

  5. A collection of objects that use a common structure and a common behavior is known as-

    • a)Object
    • b)Entity
    • c)Instance
    • d)Class (correct answer)
    Explanation · ব্যাখ্যা

    Correct answer: (d) Class

    A class defines the fields (structure) and methods (behaviour) that all of its objects share. Every object created from it has the same set of fields and responds to the same methods, though each holds its own values. A group of objects with a common structure and common behaviour is therefore described by one class; Oracle calls a class "the blueprint from which individual objects are created".

    Why the other options are wrong

    • (a) Object: a single member of the group, with its own state; the group as a whole is described by the class.
    • (b) Entity: a data-modelling (ER diagram) term for a real-world thing whose data is stored. It is not the OOP name for objects that share structure and behaviour.
    • (c) Instance: just another word for one object created from a class.

    Tip: class = blueprint (shared structure + behaviour); object = instance = one concrete thing built from it.

    Source: What Is a Class? (The Java Tutorials, Oracle)

  6. What are the inbuit classes?

    Model answer on the paper page

  7. Hadoop is written in which language?

    • a)Java (correct answer)
    • b)C++
    • c)Pascal
    • d)Kotlin
    Explanation · ব্যাখ্যা

    Correct answer: (a) Java

    Apache Hadoop is the open-source framework for storing very large data sets across a cluster (HDFS, the Hadoop Distributed File System) and processing them in parallel (MapReduce). The framework is written in Java: its daemons run on the Java Virtual Machine, and its native MapReduce programming interface is a Java API. That is why Hadoop programming is usually learned through Java.

    Why the other options are wrong

    • (b) C++: C++ is not Hadoop's implementation language; the framework runs on the JVM.
    • (c) Pascal: A structured teaching language from the 1970s. It has no role in Hadoop.
    • (d) Kotlin: A newer JVM language best known for Android apps. Hadoop is not written in it.

    Tip: Hadoop = Java framework on the JVM (HDFS for storage + MapReduce for processing).

    Source: What is Hadoop? | IBM

  8. Explain the various types of access specifiers.

    Model answer on the paper page

  9. Define Class and Object in C++ with example.

    Model answer on the paper page

  10. What is Polymorphism? Java language এর আলোকে ব্যাখ্যা কর।

    Model answer on the paper page

  11. Which of the following is not a method of the Thread class?

    • a)sleep(long msec)
    • b)stop()
    • c)go() (correct answer)
    • d)yield()
    Explanation · ব্যাখ্যা

    Correct answer: (c) go()

    The java.lang.Thread API includes start(), run(), sleep(long millis), join(), yield(), interrupt(), isAlive(), setPriority() and others, but no go() method. A thread is launched with start(), which makes the JVM call run() on the new thread.

    Why the other options are wrong

    • (a) sleep(long msec): A real static method, Thread.sleep(long millis). It pauses the current thread for the given number of milliseconds (the parameter name in the option does not matter).
    • (b) stop(): A real method, though deprecated because stopping a thread this way is inherently unsafe (it releases all monitors and can leave shared objects inconsistent). Deprecated still means it exists in the class.
    • (d) yield(): A real static method that hints to the scheduler that the current thread is willing to give up the processor.

    Tip: Thread life cycle: start() → run(); pause with sleep(), wait for another thread with join(), give way with yield(). There is no go().

    Source: Thread (Java Platform SE 8) - Oracle API documentation

  12. What is the difference between OOP and POP?

    Model answer on the paper page

Common mistakes · সাধারণ ভুল

  • Mixing up encapsulation and abstraction: encapsulation hides data with access modifiers, abstraction hides implementation behind abstract classes and interfaces.
  • Saying overloading needs inheritance: overloading works inside one class; overriding needs a parent and a child.
  • Giving a constructor a return type (even void): then it is an ordinary method, not a constructor.
  • Claiming Java supports multiple inheritance of classes or has destructors: it supports multiple interfaces and uses garbage collection.
  • Forgetting virtual in C++: without it, a call through a base pointer runs the base version (static binding).
  • Treating static members as per-object: a static variable has one copy shared by every object of the class.

বাংলায় সংক্ষেপে

  • ক্লাস হলো ব্লুপ্রিন্ট বা ইউজার-ডিফাইনড টাইপ; অবজেক্ট তার ইনস্ট্যান্স। ক্লাসে ডেটা ও ফাংশন দুটোই থাকে।
  • চারটি স্তম্ভ: এনক্যাপসুলেশন (ডেটা লুকানো), অ্যাবস্ট্রাকশন (ইমপ্লিমেন্টেশন লুকানো), ইনহেরিট্যান্স (is-a), পলিমরফিজম (এক নাম, বহু রূপ)।
  • ওভারলোডিং = কম্পাইল-টাইম বা স্ট্যাটিক বাইন্ডিং; ওভাররাইডিং = রান-টাইম বা ডাইনামিক বাইন্ডিং (সি++-এ virtual লাগে)।
  • কনস্ট্রাক্টরের নাম ক্লাসের নামে, কোনো রিটার্ন টাইপ নেই; ডেস্ট্রাক্টর ~ClassName()। জাভায় ডেস্ট্রাক্টর নেই, গার্বেজ কালেক্টর আছে।
  • ইনহেরিট্যান্সে আগে বেস ক্লাসের কনস্ট্রাক্টর চলে, আর ডেস্ট্রাক্টর চলে উল্টো ক্রমে।
  • জাভা ক্লাসে মাল্টিপল ইনহেরিট্যান্স নেই, ইন্টারফেসে আছে; সি++ ডায়মন্ড সমস্যা virtual ইনহেরিট্যান্স দিয়ে সমাধান করে।
  • সি++ ক্লাসে মেম্বার ও ইনহেরিট্যান্স ডিফল্টভাবে private; বেস ক্লাসের private মেম্বার ডিরাইভড ক্লাসে সরাসরি ব্যবহার করা যায় না।

Updated 2026-10-18. Written by ARBS Academy; the past exam questions are from public recruitment exams.