Test Series - oops

Test Number 2/78

Q: Why Java is Partially OOP language?
A. It supports usual declaration of primitive data types
B. It doesn’t support all types of inheritance
C. It allows code to be written outside classes
D. It does not support pointers
Solution: As Java supports usual declaration of data variables, it is partial implementation of OOP. Because according to rules of OOP, object constructors must be used, even for declaration of variables.
Q: Which concept of OOP is false for C++?
A. Code can be written without using classes
B. Code must contain at least one class
C. A class must have member functions
D. At least one object should be declared in code
Solution: In C++, it’s not necessary to use classes, and hence codes can be written without using OOP concept. Classes may or may not contain member functions, so it’s not a necessary condition in C++. And, an object can only be declared in a code if its class is defined/included via header file.
Q: Which header file is required in C++ to use OOP?
A. iostream.h
B. stdio.h
C. stdlib.h
D. OOP can be used without using any header file
Solution: We need not include any specific header file to use OOP concept in C++, only specific functions used in code need their respective header files to be included or classes should be defined if needed.
Q: Which of the two features match each other?
A. Inheritance and Encapsulation
B. Encapsulation and Polymorphism
C. Encapsulation and Abstraction
D. Abstraction and Polymorphism
Solution: Encapsulation and Abstraction are similar features. Encapsulation is actually binding all the properties in a single class or we can say hiding all the features of object inside a class. And Abstraction is hiding unwanted data (for user) and showing only the data required by the user of program.
Q: Which feature allows open recursion, among the following?
A. Use of this pointer
B. Use of pointers
C. Use of pass by value
D. Use of parameterized constructor
Solution: Use of this pointer allows an object to call data and methods of itself whenever needed. This helps us call the members of an object recursively, and differentiate the variables of different scopes.
Q: Which of the following is not type of class?
A. Abstract Class
B. Final Class
C. Start Class
D. String Class
Solution: Only 9 types of classes are provided in general, namely, abstract, final, mutable, wrapper, anonymous, input-output, string, system, network. We may further divide the classes into parent class and subclass if inheritance is used.
Q: Class is pass by _______
A. Value
B. Reference
C. Value or Reference, depending on program
D. Copy
Solution: Classes are pass by reference, and the structures are pass by copy. It doesn’t depend on the program.
Q: What is default access specifier for data members or member functions declared within a class without any specifier, in C++?
A. Private
B. Protected
C. Public
D. Depends on compiler
Solution: The data members and member functions are Private by default in C++ classes, if none of the access specifier is used. It is actually made to increase the privacy of data.
Q: Which is most appropriate comment on following class definition?

class Student 
{
    int a; 
    public : float a; 
};
A. Error : same variable name can’t be used twice
B. Error : Public must come first
C. Error : data types are different for same variable
D. It is correct
Solution: Same variable can’t be defined twice in same scope. Even if the data types are different, variable name must be different. There is no rule like Public member should come first or last.
Q: Which is known as a generic class?
A. Abstract class
B. Final class
C. Template class
D. Efficient Code
Solution: Template classes are known to be generic classes because those can be used for any data type value and the same class can be used for all the variables of different data types.

You Have Score    /10