Simple Aptitude:
a) Question: Determine the next number in the sequence: 2, 4, 6, 8, ...?
Answer: The next number in the sequence is 10. Each number is obtained by adding 2 to the previous number, resulting in a linear progression.
b) Question: Calculate the cost of 5 apples if 3 apples cost $1.50.
Answer: The cost of 5 apples would be $2.50. By proportionally scaling the cost, we find that each apple costs $0.50, and multiplying by 5 gives the total cost.
C Language:
a) Question: What is the output of the code snippet that increments and prints a variable x?
Answer: The output depends on the initial value of x. If x starts at 0, the output will be 1. The snippet likely contains x++ followed by a print statement, which increments x and then prints its value.
b) Question: Identify the keyword used to declare constants in C.
Answer: In C, the const keyword is used to declare constants. Constants are variables whose values cannot be changed once assigned, providing immutability to the declared value.
C++ Language:
a) Question: Provide the correct syntax to define a class named Car in C++.
Answer: The correct syntax to define a class named Car in C++ is:
cpp
Copy code
class Car {
// Class members and methods go here
};
This defines a blueprint for objects of type Car, encapsulating its properties and behaviors.
b) Question: Select the invalid data type among int, char, string, and byte.
Answer: In C++, byte is not a built-in data type. Instead, you would typically use unsigned char or std::byte for byte-sized data. The other options, int, char, and string, are valid data types in C++.
OOP Concepts:
a) Question: Define the OOP concept involving hiding internal state and mandating interaction via object methods.
Answer: The OOP concept is encapsulation. Encapsulation involves bundling the data (variables) and methods (functions) that operate on the data into a single unit, thus hiding the internal state of an object and restricting access to it.
b) Question: Name the OOP concept that allows a class to have multiple methods with the same name but different parameters.
Answer: This concept is called method overloading. Method overloading enables a class to define multiple methods with the same name but different parameter lists, providing flexibility and improving code readability.