পরীক্ষা আর্কাইভ

৪৯তম বিসিএস ⎯ তথ্য ও যোগাযোগ প্রযুক্তি [২৮১]

পরীক্ষা৪৯তম বিসিএস ⎯ তথ্য ও যোগাযোগ প্রযুক্তি [২৮১]তারিখতারিখ অনির্ধারিতসময়16 minutes
মোট প্রশ্ন২৯
সিলেবাস
Exam 4 Structured programming language, Functions and program structure, Input and Output, Object Oriented Programing language, Inheritance. [Source: Class-4 and relevant books]
ঘনত্ব
উত্তর
উত্তরিতবর্তমানপুনরায় দেখুনঅসম্পূর্ণ

৪৯তম বিসিএস ⎯ তথ্য ও যোগাযোগ প্রযুক্তি [২৮১]

৪৯তম বিসিএস ⎯ তথ্য ও যোগাযোগ প্রযুক্তি [২৮১] · তারিখ অনির্ধারিত · ২৯ প্রশ্ন

.
Which control structures are primarily used in structured programming?
  1. Sequence, Selection, and Iteration
  2. Sequence, Branching, and Randomization
  3. Sequence, Looping, and Arbitrary Jumps
  4. Selection, Randomization, and Spontaneous Control
ব্যাখ্যা

Structured programming relies on three fundamental control structures:

Sequence: The default control structure, where statements are executed one after the other.
Selection: Conditional statements (if, else, switch) allow the program to choose between two or more paths based on certain conditions.
Iteration: Looping structures (for, while, do-while) enable the program to repeat tasks a certain number of times or until a condition is met.

These control structures ensure that the program’s flow is logical and predictable, which is a core principle of structured programming. Arbitrary jumps (goto statements) and randomization are discouraged in structured programming because they make the flow of control unpredictable and hard to follow.

Source: Data Communications and Networking by Behrouz A. Forouzan

.
Which of the following is the primary benefit of modularizing a program using functions or procedures in structured programming?
  1. Increased program execution speed
  2. Reduced program size
  3. Easier code maintenance and readability
  4. Elimination of all errors
ব্যাখ্যা

Dividing a program into smaller functions or procedures makes the code modular. This modularity improves the program's readability and maintainability because each function or procedure has a specific task and can be independently modified or tested. Functions also help avoid code duplication, making it easier to update the program without affecting other parts.

Source: Digital Design (6th Global Edition) by M. Morris Mano

.
Which construct is the structured replacement for a counting loop implemented with manual jumps?
  1. if
  2. for
  3. goto
  4. break
ব্যাখ্যা

The for loop is the structured replacement for a counting loop that was traditionally implemented with manual jumps using goto.

• 'goto' is typically used to manually jump between sections of code, which is considered unstructured and hard to maintain.
• The for loop provides a more structured and clear way to handle counting iterations, where the initialization, condition checking, and iteration are all handled within the loop construct itself.
Example of a counting loop using goto (unstructured):
int i = 0;
start:
if (i < 10) {
printf("%d\n", i);
i++;
goto start;
}

Structured version using for:

for (int i = 0; i < 10; i++) {
printf("%d\n", i);
}

Thus, the for loop is the most appropriate and structured alternative for a counting loop implemented with manual jumps.
• 'if' is a conditional statement used for decision-making, not for counting loops.
• 'goto' is unstructured and allows arbitrary jumps, which is the opposite of structured programming.
• 'break' is used to exit a loop prematurely, but it is not a replacement for a counting loop itself.

 Source: Programming in C by Stephen G. Kochan

.
Which of the following control structures would be used for decision-making in structured programming?
  1. while loop
  2. for loop
  3. goto statement
  4. if statement
ব্যাখ্যা

The if statement used for decision-making because of the following reasons:
Condition Checking: The if statement allows you to check if a specific condition is true or false. If the condition is true, the block of code associated with the if statement is executed.
Branching: It lets the program branch into different sections based on the evaluation of the condition. This helps control the flow of the program and allows the program to take different actions depending on different scenarios.
Control Flow: In structured programming, control flow is predictable and easily traceable. The if statement keeps this flow organized by allowing the program to choose from alternative paths based on logical conditions.
Example of if statement:

int age = 20;
if (age >= 18) {
printf("You are an adult.\n");
} else {
printf("You are a minor.\n");
}

In this example:
• If age >= 18 is true, the program will print "You are an adult."
• If the condition is false, the program will print "You are a minor."

Source: Programming in C by Stephen G. Kochan

.
What is the correct way to define a function in C?
  1. int function_name() { }
  2. void function_name() { }
  3. return function_name() { }
  4. Both a and b
ব্যাখ্যা

In C, functions can be defined to return a specific data type (like int, float, etc.) or no value at all using void. The return type must be followed by the function's name and parameter list.

Example:

int add(int a, int b) { // Function returning an int value
return a + b;
}

void greet() { // Function returning nothing (void)
printf("Hello, World!\n");
}

Summary:
In C programming:

• int function_name() is used when a function returns an integer value.
• void function_name() is used when the function does not return anything.

Both int and void are valid return types for functions in C, depending on whether you want the function to return a value.

Source: Programming in C by Stephen G. Kochan

.
Which of the following is NOT a valid function signature in C?
  1. int add(int a, int b);
  2. void print();
  3. int add(int a, b);
  4. float multiply(int a, float b);
ব্যাখ্যা

In C, when declaring a function, the data type of each parameter must be specified. In option 'int add(int a, b);', the parameter b does not have a data type, which makes it an invalid function signature. Each parameter must be declared with a type, such as int, float, etc.


Example:

int add(int a, int b) { // Correct function declaration
return a + b;
}

void print() { // Correct function declaration with no parameters
printf("Hello, World!\n");
}

Source: The C Programming Language by Brian W. Kernighan and Dennis M. Ritchie

.
Which of the following is the correct way to call a function in C?
  1. function_name();
  2. call function_name();
  3. invoke function_name();
  4. function_name[];
ব্যাখ্যা

In C, a function is called by simply using the function name followed by parentheses. If the function has parameters, the corresponding arguments are passed inside the parentheses.

Example:

void greet() {
printf("Hello!\n");
}

int main() {
greet(); // Correct function call
return 0;
}

Source: The C Programming Language by Brian W. Kernighan and Dennis M. Ritchie

.
Which of the following is the correct way to define a recursive function in C?
  1. void recursive() { recursive(); }
  2. void recursive() { if (condition) { recursive(); } }
  3. recursive() { recursive(); }
  4. recursive() { recursive(); return 0; }
ব্যাখ্যা

A recursive function is a function that calls itself in its body. However, for recursion to work correctly, it is essential to have a base case to stop the recursion, otherwise it will result in infinite recursion and stack overflow.

Break down the options:
Option ক: void recursive() { recursive(); }
This is incorrect because it calls the function recursively without any condition or base case. This will result in infinite recursion and eventually a stack overflow error.

Option খ: void recursive() { if (condition) { recursive(); } }
This is the correct way to define a recursive function. The if (condition) part ensures that the function will call itself only under a certain condition (which usually reduces the problem size in each recursive call). When the base case is met, the function will stop calling itself, thereby avoiding infinite recursion.

Option গ: recursive() { recursive(); }
This is incorrect because it lacks the return type and the necessary base case. Also, it doesn’t define what the function should return (if anything).

Option ঘ: recursive() { recursive(); return 0; }
This is incorrect for two reasons:
• It lacks the return type (e.g., void or int).
• It also calls itself indefinitely without a stopping condition (i.e., no base case).

Source: The C Programming Language by Brian W. Kernighan and Dennis M. Ritchie

.
Which of the following is not correct variable type?
  1. float 
  2. real 
  3. int
  4. double 
ব্যাখ্যা

In C, C++, and Java, the standard primitive numeric data types are:

int → for integers (whole numbers).
float → for single-precision floating-point numbers.
double → for double-precision floating-point numbers.

real is not a standard variable type in C, C++, or Java.
It is sometimes used as a keyword or alias in other programming languages (e.g., Pascal or Fortran) to represent floating-point values, but it is not valid in the C/C++/Java family, which BCS exams usually focus on.

Breakdown of Options
ক) float 
Used for decimal (fractional) numbers with single precision.
Example:
float marks = 85.75;

খ) real (Not valid in C/Java)
• Not recognized as a primitive type in C or Java.
• May exist in Pascal/Fortran, but not in standard structured languages used in BCS exams.

গ) int 
Used for whole numbers (integers).
Example:
int age = 25;

ঘ) double 
Used for decimal (fractional) numbers with double precision (higher accuracy than float).
Example:
double pi = 3.14159265359;

Source: Digital Logic and Computer Design by  M. Morris Mano

১০.
Which function does recursion call in C programming?
  1. The function returns to itself.
  2. The function calls itself.
  3. The function calls another function.
  4. The function calls the main function.
ব্যাখ্যা

In recursion, a function calls itself in order to solve a smaller instance of the problem. This process continues until the base case is reached, at which point the recursion stops, and the function starts returning values back to the previous calls.

Option Breakdown:
Option ক) Incorrect: The function does not "return" to itself; it calls itself.
Option খ) Correct: In recursion, the function calls itself with updated parameters (usually smaller values) to approach the base case.
Option গ) Incorrect: Recursion specifically involves a function calling itself, not another function.
Option ঘ) Incorrect: Recursion does not involve calling the main() function.

Example of Recursion:


In the factorial() function, it calls itself with n-1 until the base case n == 0 is met.

Source:  The C Programming Language by Brian W. Kernighan and Dennis M. Ritchie 

১১.
Which of the following is used for input-output (I/O) operations in C?
  1. stdlib.h
  2. stdio.h
  3. math.h
  4. string.h
ব্যাখ্যা

The stdio.h (standard input-output header) is used for input and output operations in C. It includes functions like printf() for output, scanf() for input, getchar() and putchar() for character I/O, and many others.

Option Breakdown:

Option ক) stdlib.h: This header file provides functions for memory allocation, process control, conversions, and others (like malloc(), free(), exit()).
Option খ) stdio.h: Correct. This is the correct header file for handling input and output functions.
Option গ) math.h: This header file provides mathematical functions such as sqrt(), pow(), sin(), and cos().
Option ঘ) string.h: This header file provides string manipulation functions like strlen(), strcpy(), and strcmp().

Example of using stdio.h:



Source: The C Programming Language by Brian W. Kernighan and Dennis M. Ritchie

১২.
The data type 'char' in C is used to store:
  1. Integer numbers
  2. Floating-point numbers
  3. Single characters
  4. Large decimal numbers
ব্যাখ্যা

In C, the char data type is used to store a single character. It typically takes up 1 byte of memory and can store alphabetic characters, digits, and special symbols in the form of their corresponding ASCII values.

Option ক) is incorrect because integer numbers are stored using int or long types.
Option খ) is incorrect because floating-point numbers are stored using float or double types.
Option গ) is correct because char is specifically designed to store single characters such as 'a', '1', '#', etc.
Option ঘ) is incorrect because large decimal numbers are stored using float or double, not char.

Example:


Source: The C Programming Language by Brian W. Kernighan and Dennis M. Ritchie

১৩.
Which of the following is NOT a valid integer type modifier in C?
  1. short
  2. long
  3. huge
  4. unsigned
ব্যাখ্যা

In C, integer types can be modified by certain keywords to adjust their size or whether they are signed or unsigned. The valid integer type modifiers are:

short: Modifies an integer to be shorter in size (typically 2 bytes).
long: Modifies an integer to be longer in size (typically 4 or 8 bytes).
unsigned: Modifies an integer to represent only non-negative values, doubling the range of positive values.

huge is NOT a valid integer modifier in C. It is sometimes seen in older compilers (like Turbo C) as a modifier for large memory models but is not valid in modern C standards.

Option Breakdown:

 Option ক) short: Correct modifier in C to create a smaller integer type (typically 2 bytes).
 Option খ) long: Correct modifier in C to create a larger integer type (typically 4 or 8 bytes).
 Option গ) huge: Incorrect modifier. It is not supported in standard C.
 Option ঘ) unsigned: Correct modifier in C that allows the integer to hold only positive values (including zero).


Source: The C Programming Language by Brian W. Kernighan and Dennis M. Ritchie

১৪.
Which of the following is a derived data type in C?
  1. int
  2. float
  3. array
  4. char
ব্যাখ্যা

Derived data types are types that are based on fundamental data types but are more complex. Arrays are derived data types because they allow you to store multiple values of the same type in a single variable.

Option ক) is incorrect. int is a basic data type in C, not a derived type. It is used to store integer values.
Option খ) is incorrect. float is a basic data type in C, used to store floating-point numbers.
Option গ) is correct. Array is a derived data type because it is created using a basic data type (e.g., int, float, char) to store multiple values of the same type.
Option ঘ) is incorrect. char is a basic data type in C, used to store a single character.
​Example:

Source: The C Programming Language by Brian W. Kernighan and Dennis M. Ritchie

১৫.
Which of the following is scanf() used for?
  1. Displaying output
  2. Taking input from the user
  3. Performing mathematical calculations
  4. Declaring a variable
ব্যাখ্যা

The scanf() function in C is specifically designed for taking input from the user. It reads data from the standard input (usually the keyboard) and stores it in the provided variables. The scanf() function uses format specifiers (such as %d for integers, %f for floating-point numbers) to read various types of data.

Option Breakdown:

 Option ক) Displaying output: This is incorrect. scanf() is for input, not output. For displaying output, the printf() function is used.

 Option খ) Taking input from the user: This is correct. scanf() is used for accepting user input, whether it's integers, characters, or strings.

 Option গ) Performing mathematical calculations: This is incorrect. scanf() does not perform mathematical calculations. scanf() is used for reading input, not performing operations. Mathematical calculations are done using arithmetic operators or functions like +, -, *, /.

 Option ঘ) Declaring a variable: This is incorrect. scanf() does not declare variables. Variables are declared using a data type (e.g., int, float, char), and scanf() is used to assign values to those variables.

Example of scanf() usage:

​In this example, scanf("%d", &age); reads an integer from the user and stores it in the age variable.

Source: The C Programming Language by Brian W. Kernighan and Dennis M. Ritchie

১৬.
Which of the following is used to represent double precision floating-point numbers in C?
  1. %c
  2. %d
  3. %lf
  4. %s
ব্যাখ্যা

In C, the %lf format specifier is used to print double precision floating-point numbers (i.e., double type) in printf() and scanf(). Although the %f specifier is used for both float and double in scanf(), in printf(), you must use %lf for double to ensure correct representation.

Option Breakdown:

Option ক) %c: Incorrect. The %c specifier is used to print single characters.
Option খ) %d: Incorrect. The %d specifier is used for printing integers.
Option গ) %lf: Correct. The %lf specifier is used for printing double precision floating-point numbers.
Option ঘ) %s: Incorrect. The %s specifier is used to print strings.

Example:

​In this example, the %lf format specifier is used to correctly print a double precision floating-point number (pi).

Source: The C Programming Language by Brian W. Kernighan and Dennis M. Ritchie

১৭.
Which symbol is used in scanf() to specify a variable’s memory address?
  1. *
  2. &
  3. %
  4. #
ব্যাখ্যা

The scanf() function in C is used to take input from the user.
Its syntax:
                          scanf("format_specifier", &variable);

scanf() requires the memory address of a variable so it can store the user’s input in that location.
The symbol & (ampersand) is called the address-of operator. It is used to pass the address of the variable to scanf().
 Without &, scanf() would not know where to store the value, leading to runtime errors or unexpected behavior.

​Option Breakdown

ক) * (asterisk) → Used in pointer declaration/dereferencing, not for scanf().
Example: int *p; or *p = 10;.

খ) & (ampersand) → Used to pass the address of a variable to scanf().

গ) % (percent) → Used inside scanf() or printf() as a format specifier.
Example: %d for integer, %f for float.

ঘ) # (hash) → Used for preprocessor directives (like #include, #define).


Source: Digital Logic & Computer Design by M. Morris Mano

১৮.
What will happen if you forget to use & in scanf()?
  1. Compiler error
  2. Garbage value may be stored
  3. Program crash (undefined behavior)
  4. Nothing will happen
ব্যাখ্যা

In C, scanf() needs the memory address of a variable so it can store the user’s input there.

Normally we write:

int x;
scanf("%d", &x); // passing the address of x

If you write instead:

scanf("%d", x); // forgot the &

then scanf() interprets the integer value of x (which is uninitialized garbage at this point) as a memory address where it should write the input.

​Undefined behavior:
• Sometimes the program crashes immediately (segmentation fault).
• Sometimes it overwrites random memory locations, causing future crashes.
• Rarely, it may appear to work but store garbage.

​Option Breakdown

ক) Compiler error →The compiler does not give an error, because technically scanf("%d", num); passes an int value, which is treated as a pointer (wrongly).

খ) Garbage value may be stored →  (partially true but not the full picture)
Sometimes it happens, but more correctly, the behavior is undefined, not guaranteed garbage.

গ) Program crash (undefined behavior) → Correct. Forgetting & causes undefined behavior, which usually results in a crash or memory corruption.

ঘ) Nothing will happen → Wrong. Something will happen, but unpredictably.

Source: Structured Programming Concepts by Tanenbaum

১৯.
Which function can be used to read an entire line of text, including spaces?
  1. scanf()
  2. getchar()
  3. fgets()
  4. puts()
ব্যাখ্যা

fgets() is used to read an entire line of text, including spaces, from the standard input.
scanf() stops reading at the first whitespace (space, tab, or newline), so it cannot be used to read a line with spaces.
getchar() reads one character at a time, not a line.
puts() is used to print strings, not to read them.

​Example:

Source: The C Programming Language by Brian W. Kernighan and Dennis M. Ritchie

২০.
Which of the following is the latest Object-Oriented Programming (OOP) language?
  1. C++
  2. Java
  3. Python
  4. Swift
ব্যাখ্যা

Swift: Swift is the most recent object-oriented programming language in this list, introduced by Apple in 2014.
​Swift is a modern, high-performance language developed by Apple for building iOS, macOS, watchOS, and tvOS applications. It was introduced by Apple in 2014 as a more efficient and safer alternative to Objective-C. Swift is object-oriented, and it incorporates features from other programming paradigms, such as protocol-oriented programming and functional programming.

C++: C++ was created by Bjarne Stroustrup in 1979 as an extension to the C language, adding object-oriented features. It is one of the oldest OOP languages still widely used, especially in system-level programming.

Java: Java, created by Sun Microsystems in the mid-1990s, is an OOP language widely used for building cross-platform applications (e.g., mobile apps, enterprise solutions). Java was designed with the idea of writing once, running anywhere (WORA), making it a popular choice for large-scale applications.

Python: Python, created by Guido van Rossum in the late 1980s and officially released in 1991, is also an object-oriented language. It is known for its simplicity and readability. Python is widely used in data science, web development, and automation.

​Source: The C Programming Language by Brian W. Kernighan and Dennis M. Ritchie

২১.
Which modeling is the process of creating a simplified visual diagram of a software system?
  1. Data modeling
  2. Process modeling
  3. Object modeling
  4. Structural modeling
ব্যাখ্যা

Structural modeling refers to the process of creating simplified visual diagrams (such as UML diagrams) that represent the structure of a software system. It shows how different components of the system are organized and how they interact with each other.

Structural modeling focuses on defining the structure and relationships between various elements in the software system, such as classes, objects, and data structures.

Option Breakdown:

 Option ক) Data modeling: Data modeling focuses on how data is structured and organized. It typically involves creating an abstract representation of the data structures (like ER diagrams).
 Option খ) Process modeling: Process modeling focuses on how processes in the system work and how they interact with each other, such as workflow diagrams or activity diagrams.
 Option গ) Object modeling: Object modeling refers to the representation of the system's objects (including classes and objects in OOP), but it is not as general as structural modeling, which covers broader system aspects.
 Option ঘ) Structural modeling: Correct. Structural modeling is the creation of simplified visual diagrams to represent the structure and organization of a software system. Examples include class diagrams, component diagrams, and deployment diagrams.

Example of Structural Modeling (UML Class Diagram):
​ +-----------------+
 |         Car             |
+-----------------+
|  - model: String  |
|  - color: String    |
+-----------------+
|   + start(): void   |
+-----------------+

​This is an example of a class diagram, which is part of structural modeling. It represents the Car class, its attributes (model and color), and its method (start).

​Source: Object-Oriented Modeling and Design by James Rumbaugh

২২.
Which type of inheritance is shown below?

  1. Multiple Inheritance
  2. Multilevel Inheritance
  3. Single Inheritance
  4. Hybrid Inheritance
ব্যাখ্যা

Single Inheritance occurs when a derived class inherits from a single base class. In this case, class B inherits from class A. Hence, it is single inheritance.

Option Breakdown:

ক) Multiple Inheritance: This is when a derived class inherits from multiple base classes. Example: class B : public A, public C {}. This is not the case here, as B is inheriting from only one class A.

খ) Multilevel Inheritance: This occurs when a class inherits from another derived class. Example: class C : public B {}, where B is derived from A. In the given code, there is no multilevel chain; B directly inherits from A.

গ) Single Inheritance: Correct. Single inheritance is when one class inherits from only one base class. In the given example, B is inheriting from a single base class A.

ঘ) Hybrid Inheritance: This occurs when a class combines multiple types of inheritance (e.g., a combination of single and multiple inheritance). This is not applicable in the given code.

Source: ​Object Oriented Programming in C++ by Robert Lafore

২৩.
Which of the following variables is 'name' in declared as private in a class?
  1. string name;
ব্যাখ্যা

In C++ (and many other object-oriented languages), the access modifiers (public, private, protected) control the visibility of class members (variables and functions).

Private variables:
• Private variables can only be accessed or modified within the class in which they are declared.
• Private variables cannot be accessed directly from outside the class. Access to these variables is typically controlled through getter and setter methods (public methods).

Public variables:
Public variables can be accessed and modified from anywhere, both inside and outside the class.

Protected variables:
Protected variables can be accessed within the class and by derived classes (child classes), but not from outside the class.

Global variables:
A variable declared outside any class or function is a global variable. It is accessible from anywhere in the program (which is generally not recommended in OOP).

Option Breakdown:

 Option ক) Incorrect: name is declared as public in this class, meaning it can be accessed directly from outside the class, which does not make it private.
 Option খ) Correct: name is declared as private in this class. This means it can only be accessed and modified inside the class, not from outside the class.
 Option গ) Incorrect: name is declared as protected in this class, meaning it can be accessed within the class and by derived classes, but it is not private.
 Option ঘ) Incorrect: This is a global variable, not a class variable. A global variable is declared outside of any class or function, making it accessible from anywhere in the program.

​Source: The C++ Programming Language by Bjarne Stroustrup

২৪.
Which of the following is the key feature of Object-Oriented Programming (OOP)?
  1. Functions
  2. Objects
  3. Procedures
  4. Loops
ব্যাখ্যা

Objects are the central unit in Object Oriented Programming (OOP), encapsulating data and behavior.
​The key feature of Object-Oriented Programming (OOP) is the concept of "objects." 
​Objects are instances of classes, and they encapsulate data and methods that operate on the data. The primary focus of OOP is to design software around these objects, which represent real-world entities.

Option Breakdown:

Functions: While functions are part of OOP, they are not the central feature. Functions operate on objects.
Procedures: Procedures are typically used in procedural programming, not specifically in OOP.
Loops: Loops are control structures used in many programming paradigms, including OOP, but they are not the defining feature of OOP.


Source: Object-Oriented Programming in C++ by Robert Lafore

২৫.
Which of the following allows an object to take on multiple forms in OOP?
  1. Inheritance
  2. Polymorphism
  3. Encapsulation
  4. Abstraction
ব্যাখ্যা

Polymorphism: Polymorphism allows an object to take on different forms based on the method or class context.
Polymorphism in OOP allows an object to take on many forms. This can happen in two ways:

Method Overloading: Multiple methods with the same name but different parameters.
Method Overriding: In derived classes, methods can be overridden to provide different implementations.

​Option Breakdown:

Inheritance: Inheritance allows one class to derive from another but does not allow objects to take on different forms.

Encapsulation: Encapsulation is about bundling data and methods together and restricting access but not about multiple forms.
Abstraction: Abstraction hides complex details but doesn’t involve objects taking on multiple forms.

Source: C++ Programming Language by Bjarne Stroustrup

২৬.
Which of the following types of inheritance allows a class to inherit from more than one class?
  1. Single Inheritance
  2. Multilevel Inheritance
  3. Multiple Inheritance
  4. Hierarchical Inheritance
ব্যাখ্যা

Multiple Inheritance: Multiple inheritance allows a class to inherit from more than one base class, meaning it can derive features from multiple parent classes. This can be useful in certain cases, but it can also lead to complexity, especially when there is ambiguity in the inheritance hierarchy.

​Option Breakdown:

Single Inheritance: This involves inheriting from only one parent class.
Multilevel Inheritance: This involves a class inheriting from a derived class, forming a multi-level chain (e.g., A → B → C).
Hierarchical Inheritance: In this type, multiple classes inherit from a single parent class.

Source: C++ Programming by D.S. Malik

২৭.
Which keyword is used to inherit from a base class in C++?
  1. super
  2. inherit
  3. base
  4. public
ব্যাখ্যা

In C++, the keyword used to define inheritance is public (or other access specifiers like protected and private). By default, all members of the base class (parent class) are inherited as private if not specified, but using public inheritance allows the public and protected members of the parent class to be accessible to the subclass.

​Example:

​Here, the Dog class publicly inherits from the Animal class, allowing it to access the eat() method.

Option Breakdown:

super: This keyword is used in languages like Java, not C++.
inherit: There is no inherit keyword in C++.
base: This keyword is not used in inheritance.
public: The public keyword is used to specify inheritance in C++ and maintain the accessibility of the base class members.

Source: Object-Oriented Programming with C++ by E. Balagurusamy

২৮.
In inheritance, what is the term for the class that is inherited from?
  1. Base class
  2. Child class
  3. Superclass
  4. Parent class
ব্যাখ্যা

In inheritance, the base class (also called the parent class or superclass) is the class from which properties and methods are inherited. A subclass or child class inherits these properties and behaviors from the base class.

​Example:

 

​Option Breakdown:

Base class:  The base class is the class from which inheritance happens.
Child class: This is the subclass that inherits from the base class.
Superclass: Another name for the base class, but base class is the more commonly used term in C++.
Parent class: A synonym for base class, but the correct term is typically base class.

Source:  Object-Oriented Programming with C++ by E. Balagurusamy

২৯.
Which keyword is used to create a subclass in Java?
  1. extends
  2. inherit
  3. super
  4. subclass
ব্যাখ্যা

In Java, the extends keyword is used to create a subclass, i.e., to inherit properties and methods from a superclass. It defines the relationship between the child (subclass) and the parent (superclass).

Example:

​Here, Dog is a subclass of Animal, created using the extends keyword.

Option Breakdown:

extends: extends is the keyword used to inherit from a class in Java.
inherit: Incorrect. Java uses extends, not inherit.
super: Incorrect. super refers to the superclass and is used to call superclass methods or constructors, not to create subclasses.
subclass: Incorrect. subclass is not a keyword in Java.

Source: Head First Java by Kathy Sierra and Bert Bates