Test Series - oops

Test Number 3/78

Q: Size of a class is _____________
A. Sum of the size of all the variables declared inside the class
B. Sum of the size of all the variables along with inherited variables in the class
C. Size of the largest size of variable
D. Classes doesn’t have any size
Solution: Classes doesn’t have any size, actually the size of object of the class can be defined. That is done only when an object is created and its constructor is called.
Q: Which class can have member functions without their implementation?
A. Default class
B. String class
C. Template class
D. Abstract class
Solution: Abstract classes can have member functions with no implementation, where the inheriting subclasses must implement those functions.
Q: Which of the following describes a friend class?
A. Friend class can access all the private members of the class, of which it is a friend
B. Friend class can only access protected members of the class, of which it is a friend
C. Friend class don’t have any implementation
D. Friend class can’t access any data member of another class but can use it’s methods
Solution: A friend class can access all the private members of another class, of which it is a friend. It is a special class provided to use when you need to reuse the data of a class but don’t want that class to have those special functions.
Q: What is the scope of a class nested inside another class?
A. Protected scope
B. Private scope
C. Global scope
D. Depends on access specifier and inheritance used
Solution: It depends on the access specifier and the type of inheritance used with the class, because if the class is inherited then the nested class can be used by subclass too, provided it’s not of private type.
Q: Class with main() function can be inherited.
A. True
B. False
C. 1
D. 0
Solution: The class containing main function can be inherited and hence the program can be executed using the derived class names also in java.
Q: Which among the following is false, for a member function of a class?
A. All member functions must be defined
B. Member functions can be defined inside or outside the class body
C. Member functions need not be declared inside the class definition
D. Member functions can be made friend to another class using the friend keyword
Solution: Member functions must be declared inside class body, though the definition can be given outside the class body. There is no way to declare the member functions outside the class.
Q: Which syntax for class definition is wrong?
A. class student{ };
B. student class{ };
C. class student{ public: student(int a){ } };
D. class student{ student(int a){} };
Solution: Keyword class should come first. Class name should come after keyword class. Parameterized constructor definition depends on programmer so it can be left empty also.
Q: Which of the following pairs are similar?
A. Class and object
B. Class and structure
C. Structure and object
D. Structure and functions
Solution: Class and structure are similar to each other. Only major difference is that a structure doesn’t have member functions whereas the class can have both data members and member functions.
Q: Which among the following is false for class features?
A. Classes may/may not have both data members and member functions
B. Class definition must be ended with a colon
C. Class can have only member functions with no data members
D. Class is similar to union and structures
Solution: Class definition must end with a semicolon, not colon. Class can have only member functions in its body with no data members.
Q: Instance of which type of class can’t be created?
A. Anonymous class
B. Nested class
C. Parent class
D. Abstract class
Solution: Instance of abstract class can’t be created as it will not have any constructor of its own, hence while creating an instance of class, it can’t initialize the object members. Actually the class inheriting the abstract class can have its instance because it will have implementation of all members.

You Have Score    /10