Grade – 10 – Computer Science – Advanced Programming Concepts and Paradigms – Multiple Choice Questions

Multiple Choice Questions

Advanced Programming Concepts and Paradigms

Topic: Advanced Programming Concepts and Paradigms
Grade: 10

Question 1:
What is the purpose of encapsulation in object-oriented programming?
a) To hide the internal details of an object
b) To allow multiple objects to work together
c) To provide a way to organize code into reusable components
d) To allow objects to inherit behavior from other objects

Answer: a) To hide the internal details of an object

Explanation: Encapsulation in object-oriented programming is the process of hiding the internal details of an object and exposing only the necessary information and functionality through public methods. This helps in achieving data abstraction and ensures that the object\’s internal state cannot be directly modified. For example, a class representing a bank account may encapsulate the account balance variable and provide methods to deposit or withdraw money, hiding the actual implementation details from the outside world.

Question 2:
Which of the following is an example of a functional programming language?
a) Java
b) Python
c) Haskell
d) C++

Answer: c) Haskell

Explanation: Haskell is a purely functional programming language that follows the principles of functional programming, such as immutability, higher-order functions, and lazy evaluation. It focuses on expressing computations as mathematical functions rather than changing state or executing commands. In contrast, Java, Python, and C++ are multi-paradigm programming languages that support both functional and imperative programming styles.

Question 3:
What is the difference between procedural programming and object-oriented programming?
a) Procedural programming focuses on procedures or functions, while object-oriented programming focuses on objects and their interactions.
b) Procedural programming allows for code reusability through the use of functions, while object-oriented programming allows for code reusability through the use of classes and objects.
c) Procedural programming is more suitable for small-scale programs, while object-oriented programming is more suitable for large-scale programs.
d) Procedural programming is more efficient in terms of memory usage, while object-oriented programming is more efficient in terms of code organization.

Answer: a) Procedural programming focuses on procedures or functions, while object-oriented programming focuses on objects and their interactions.

Explanation: In procedural programming, the focus is on writing a sequence of procedures or functions that operate on data. It follows a top-down approach where the program is divided into smaller procedures that perform specific tasks. Object-oriented programming, on the other hand, focuses on objects that encapsulate both data and behavior. It follows a bottom-up approach where the program is divided into classes and objects that interact with each other. For example, in procedural programming, you may have functions like add(), subtract(), and multiply(), while in object-oriented programming, you may have objects like Rectangle, Circle, and Triangle that have their own properties and methods.

Question 4:
Which of the following is NOT a type of inheritance in object-oriented programming?
a) Single inheritance
b) Multiple inheritance
c) Multilevel inheritance
d) Hierarchical inheritance

Answer: b) Multiple inheritance

Explanation: Multiple inheritance is a feature in some object-oriented programming languages where a class can inherit from multiple parent classes. It allows a class to inherit properties and methods from more than one class. However, it can lead to complications such as the diamond problem, where a class inherits two or more methods with the same name and signature. Not all programming languages support multiple inheritance, and some languages like Java only support single inheritance.

Question 5:
What is the purpose of the \”this\” keyword in object-oriented programming?
a) To refer to the current object
b) To create a new object
c) To access static members of a class
d) To invoke superclass methods

Answer: a) To refer to the current object

Explanation: The \”this\” keyword in object-oriented programming is used to refer to the current object within a class. It is used to access the instance variables and methods of the object. By using \”this\”, we can differentiate between instance variables and local variables with the same name. For example, if a class has an instance variable called \”name\” and a method parameter also called \”name\”, we can use \”this.name\” to refer to the instance variable. This ensures that we are accessing the correct variable.

Question 6:
What is the purpose of polymorphism in object-oriented programming?
a) To allow objects to inherit behavior from other objects
b) To hide the internal details of an object
c) To provide a way to organize code into reusable components
d) To allow objects of different classes to be treated as objects of the same class

Answer: d) To allow objects of different classes to be treated as objects of the same class

Explanation: Polymorphism in object-oriented programming refers to the ability of objects of different classes to be treated as objects of the same class. It allows for code reusability and flexibility. By using polymorphism, we can write code that can work with objects of different classes as long as they implement the same interface or inherit from the same superclass. For example, a program can have a list of shapes (e.g., circles, rectangles) and treat them all as objects of the Shape class, allowing for common operations to be performed on them.

Question 7:
What is the output of the following code snippet?
int x = 5;
System.out.println(x++);
System.out.println(++x);

a) 5, 6
b) 5, 7
c) 6, 6
d) 6, 7

Answer: b) 5, 7

Explanation: The code snippet uses the post-increment operator (x++) and pre-increment operator (++x) on the variable x. In the first println statement, the value of x is printed and then incremented by 1 due to the post-increment operator, resulting in the output 5. In the second println statement, the value of x is incremented by 1 due to the pre-increment operator and then printed, resulting in the output 7.

Example:
int x = 5;
System.out.println(x++); // Output: 5
System.out.println(++x); // Output: 7

Question 8:
Which of the following is NOT a valid access modifier in Java?
a) private
b) protected
c) public
d) internal

Answer: d) internal

Explanation: In Java, the valid access modifiers are private, protected, and public. The private access modifier restricts access to the member within the same class. The protected access modifier allows access within the same class, subclasses, and classes in the same package. The public access modifier allows access from any class. The internal access modifier is not a valid access modifier in Java. It is a modifier used in some other programming languages like C# to specify that the member is accessible within the same assembly.

Question 9:
What is the output of the following code snippet?
String str = \”hello\”;
str.replace(\’l\’, \’L\’);
System.out.println(str);

a) hello
b) heLLo
c) heLo
d) heLlo

Answer: a) hello

Explanation: The replace() method in Java returns a new string with all occurrences of the specified character replaced. However, strings in Java are immutable, meaning they cannot be changed once created. In the code snippet, the result of the replace() method is not assigned to any variable, so the original string \”hello\” remains unchanged. Therefore, the output is \”hello\”.

Example:
String str = \”hello\”;
str.replace(\’l\’, \’L\’);
System.out.println(str); // Output: hello

Question 10:
What is the purpose of the \”super\” keyword in Java?
a) To refer to the current object
b) To create a new object
c) To access static members of a class
d) To invoke superclass methods

Answer: d) To invoke superclass methods

Explanation: The \”super\” keyword in Java is used to invoke methods or access members of the superclass from a subclass. It is often used when a subclass overrides a method defined in the superclass but still wants to access the superclass implementation. By using \”super.methodName()\”, we can explicitly invoke the superclass method. This is useful for implementing method overriding and achieving code reuse.

Question 11:
Which of the following is NOT a valid data type in Python?
a) int
b) float
c) char
d) str

Answer: c) char

Explanation: In Python, there is no specific data type for characters. Characters are represented as strings with a length of 1. Therefore, the char data type is not valid in Python. Instead, we can use a string with a single character to represent characters.

Question 12:
What is the output of the following code snippet?
x = [1, 2, 3]
y = x
x.append(4)
print(y)

a) [1, 2, 3]
b) [1, 2, 3, 4]
c) [1, 2, 3, 4, 4]
d) Error

Answer: b) [1, 2, 3, 4]

Explanation: In the code snippet, the list x is assigned to the variable y. Since lists are mutable in Python, both variables x and y refer to the same list object in memory. When the append() method is called on the list x, it modifies the list in place. Therefore, when the list y is printed, it reflects the changes made to the list x.

Example:
x = [1, 2, 3]
y = x
x.append(4)
print(y) # Output: [1, 2, 3, 4]

Question 13:
Which of the following is NOT a sorting algorithm?
a) Bubble sort
b) Merge sort
c) Quick sort
d) Hash sort

Answer: d) Hash sort

Explanation: Hash sort is not a known sorting algorithm. The correct term is \”hashing\”, which is a technique used for efficient data retrieval. Bubble sort, merge sort, and quick sort are well-known sorting algorithms used to arrange elements in a specific order.

Question 14:
What is the output of the following code snippet?
for i in range(5):
if i == 3:
continue
print(i)

a) 0 1 2 3 4
b) 0 1 2 4
c) 0 1 2 3
d) 0 1 2 3 4 4

Answer: b) 0 1 2 4

Explanation: The code snippet uses the continue statement inside the for loop. When i is equal to 3, the continue statement is executed, which skips the rest of the current iteration and moves to the next iteration. Therefore, the number 3 is skipped in the output.

Example:
for i in range(5):
if i == 3:
continue
print(i) # Output: 0 1 2 4

Question 15:
Which of the following is an example of a recursive function?
a) Factorial calculation
b) Bubble sort
c) Linear search
d) Binary search

Answer: a) Factorial calculation

Explanation: Recursive functions are functions that call themselves within their own definition. They are useful for solving problems that can be broken down into smaller subproblems. Factorial calculation is a classic example of a problem that can be solved using recursion. For example, the factorial of a number n is defined as n * (n-1)!, where (n-1)! is the factorial of (n-1). This recursive definition allows us to calculate the factorial of a number by repeatedly calling the factorial function with smaller numbers until we reach the base case of 0 or 1.

Leave a Comment

Your email address will not be published. Required fields are marked *

Shopping Cart
error: Content cannot be copied. it is protected !!
Scroll to Top