OOPS

Question 1

A software engineer is required to implement two sets of algorithms for a single set of matrix operations in an object oriented programming language; the two sets of algo­rithms are to provide precisions of 10-3 and 10-6, respectively. She decides to implement two classes, Low Precision Matrix and High Precision Matrix, providing precisions 10-3 and 10-6 respectively. Which one of the following is the best alternative for the imple­mentation?

    (S1) The two classes should be kept independent.
    (S2) Low Precision Matrix should be derived from High Precision Matrix.
    (S3) High Precision Matrix should be derived from Low Precision Matrix.
    (S4) One class should be derived from the other; the hierarchy is immaterial.
A
S1
B
S2
C
S3
D
S4
Question 1 Explanation: 
Note: Out of syllabus.
Question 2
Java Virtual Machine (JVM) is used to execute architectural neutral byte code. Which of the following is needed by the JVM for execution of Java Code?
A
Class loader only
B
Class loader and Java Interpreter
C
Class loader, Java Interpreter and API
D
Java Interpreter only
Question 3

Which of the following statements are true regarding C++?

(a) Overloading gives the capacity to an existing operator to operate on other data types.

(b) Inheritance in object oriented programming provides support to reusability.

(c) When object of a derived class is defined, first the constructor of derived class in executed then constructor of a base class is executed.

(d) Overloading is a type of polymorphism.
Choose the correct option from those given below:
A
(a) and (b) only
B
(a), (b) and (c) only
C
(a), (b) and (d) only
D
(b), (c) and (d) only
Question 3 Explanation: 
TRUE: Overloading gives the capacity to an existing operator to operate on other data types.
TRUE: Inheritance in object oriented programming provides support to reusability.
FALSE: When object of a derived class is defined, first the constructor of derived class in executed then constructor of a base class is executed.
2 important points Order of Constructor Call with Inheritance in C++
1. Whether derived class's default constructor is called or parameterised is called, base class's default constructor is always called inside them.
2. To call base class's parameterised constructor inside derived class's parameterised constructor, we must mention it explicitly while declaring derived class's parameterized constructor.
TRUE: Overloading is a type of polymorphism.
Question 4
Let A be the base class in C++ and B be the derived class from A with protected inheritance.
Which of the following statement is false for class B?
A
Member function of class B can access protected data of class A
B
Member function of class access public data of class A
C
Member function of class B cannot access private data of class A
D
Object of derived class B can access public base class data
Question 4 Explanation: 
A→ Base class
B→ Derived class from A with protected inheritance.
The friend functions and the member functions of a friend class can have direct access to both the PRIVATE and PROTECTED data, the member functions of a derived class can directly access only the PROTECTED data.
However, they can access the PRIVATE data through the member functions of the base class TRUE: Member function of class B can access protected data of class A
TRUE: Member function of class access public data of class A
FALSE: Member function of class B cannot access private data of class A
TRUE: Object of derived class B can access public base class data
Question 5
___________ is a class which implement lower level business abstractions required to manage the business domain class :
A
User interface class
B
System class
C
Business domain class
D
Process class
Question 5 Explanation: 
Process class is a class which implement lower level business abstractions required to manage the business domain class.
Question 6
Which of the following is not specified in Abstract data type?
A
Type
B
Set of operations on that type
C
How the type is implemented
D
(A) and (B)
Question 6 Explanation: 
An ADT does not specify how the data type is implemented.
Question 7
Given the array of integers ‘array’ shown below :



What is the output of the following JAVA statements ?

int [ ] p = new int [10];

int [ ] q = new int [10];

for (int k = 0; k < 10; k ++)

       p[k] = array [k];

q = p;

p[4] = 20;

System.out.println (array [4] + “ : ” + q[4]);

A
20 : 20
B
18 : 18
C
18 : 20
D
20 : 18
Question 7 Explanation: 

Question 8
Consider the following JAVA program :
public class First {
                public static int CBSE (int x) {
                if (x < 100) x = CBSE (x + 10);
                    return (x – 1);
                       }
     public static void main (String[] args){
      System.out.print(First.CBSE(60));
                  }
         }
What does this program print ?
A
59
B
95
C
69
D
99
Question 8 Explanation: 
Main program will call the function CBSE(60)
According to the function definition,
Function call CBSE(100) will give the value of 99,
100<100 condition is false and it will return x-1 which is 99
x=CBSE(90)
90<100 is true----> x=CBSE(100) and it will return x-1
CBSE(100) will return 99 to Function CBSE(90) and this function will return to 98(99-1).
Repeat this procedure,
CBSE(60) will return 95
Question 9
Which of the following statement(s) with regard to an abstract class in JAVA is/are TRUE ?
I. An abstract class is one that is not used to create objects.
II. An abstract class is designed only to act as a base class to be inherited by other classes.
A
Only I
B
Only II
C
Neither I nor II
D
Both I and II
Question 9 Explanation: 
Statement-I and II are TRUE
A class which is declared as abstract is known as an abstract class. It can have abstract and non-abstract methods. It needs to be extended and its method implemented. It cannot be instantiated.
Rules:
1. An abstract class must be declared with an abstract keyword.
2. It can have abstract and non-abstract methods.
3. It cannot be instantiated.
4. It can have constructors and static methods also.
5. It can have final methods which will force the subclass not to change the body of the method.
Question 10
Abstraction and encapsulation are fundamental principles that underlie the object oriented approach to software development. What can you say about the following two statements ? I. Abstraction allows us to focus on what something does without considering the complexities of how it works. II. Encapsulation allows us to consider complex ideas while ignoring irrelevant detail that would confuse us.
A
Neither I nor II is correct.
B
Both I and II are correct.
C
Only II is correct.
D
Only I is correct.
Question 10 Explanation: 
Statement-I: FALSE
→ Abstraction is a process of hiding the implementation details and showing only functionality to the user.
→ The data type created by the data abstraction process is called abstract data type(ADT).
→ ADT is a class of objects whose logical behavior is defined by a set of values and a set of operations.
Statement-II: FALSE
→ Encapsulation is a mechanism to associate the code and data.
→ Encapsulation is wrapping up of data into single unit.
Question 11
Which of the following features is the best to support JAVA application development distributed across a network of Java Virtual machines?
A
Remove Method Invocation (RMI)
B
Remote Procedure Calls (RPC)
C
Multicast sockets
D
Remote Method Invocation (RMI) or Remote Procedure Calls (RPC)
Question 12
Which of the following approach is generally adopted by C++ programming.
A
Top-down
B
Bottom-up
C
Right-left
D
Left-right
Question 12 Explanation: 
Structure/procedure oriented programming languages like C programming language follows top down approach. Whereas object oriented programming languages like C++ and Java programming language follows bottom up approach.
Question 13
Which among the following is the correct way of declaring object of a class
A
Classname objectname;
B
Class classname obj objectname;
C
Class classname obj objectname;
D
Classname obj objectname
Question 13 Explanation: 
The correct way of declaring object of a class is Classname objectname;
For example ,let there be some class of name Area. So we can declare object of Area class like,
Area A1;
Question 14
How many objects can be created in a single class?
A
1
B
2
C
3
D
as many as required
Question 14 Explanation: 
An object is nothing but an instance of a class. A class can have as many instances as required. There is no restriction on the number of objects a class can have.
Question 15
Which of this process occur automatically by JAVA run time system?
A
Serialization
B
Garbage collection
C
File Filtering
D
All the given options
Question 15 Explanation: 
Serialization and deserialization occur automatically by java runtime system, Garbage collection also occur automatically but is done by CPU or the operating system not by the java runtime system
Question 16
The ‘new’ operator in JAVA
A
Returns a pointer to a variable
B
Creates a variable called new
C
Obtains memory for a new variable
D
Tells how much memory is available
Question 16 Explanation: 
“new” operator in java is used to create a new object. And an object is nothing but an instance of a class. Some memory is allocated to each object for its execution. Hence option(C) is the correct answer.
Question 17
“this” keyword in JAVA is used to
A
Refer to current class object
B
Refer to static method of the class
C
Refer to parent class object
D
Refer to static variable of the class
Question 17 Explanation: 
“this” is a reference variable that refers to the current object of the class.
Question 18
Which of the following is NOT a type of constructor
A
Copy constructor
B
Friend constructor
C
Default constructor
D
Parameterized constructor
Question 18 Explanation: 
Parameterized constructors: Constructors that can take at least one argument are termed as parameterized constructors. When an object is declared in a parameterized constructor, the initial values have to be passed as arguments to the constructor function.
Default constructors: If the programmer does not supply a constructor for an instantiable class, Java/C++ compiler inserts a default constructor into your code on your behalf. This constructor is known as default constructor.
Copy Constructor: Copy constructors define the actions performed by the compiler when copying class objects. A Copy constructor has one formal parameter that is the type of the class (the parameter may be a reference to an object). It is used to create a copy of an existing object of the same class. Even though both classes are the same, it counts as a conversion constructor.
Question 19
Which one of the following CAN NOT be a friend
A
function
B
class
C
object
D
operator function
Question 19 Explanation: 
The function is not in the scope of the class to which it has been declared as a friend. It cannot be called using the object as it is not in the scope of that class. It can be invoked like a normal function without using the object.
Question 20
What should be the name of the constructor
A
same as object
B
same as member
C
same as class
D
same as function
Question 20 Explanation: 
Constructor: a constructor (abbreviation: ctor) is a special type of subroutine called to create an object. A constructor resembles an instance method, but it differs from a method in that it has no explicit return type, it is not implicitly inherited and it usually has different rules for scope modifiers. Constructors often have the same name as the declaring class. They have the task of initializing the object's data members
Question 21

What is the output of the following program:

#include

class sample

{

private int a,b’

public: void test ( )

{

a = 100;

b = 200;

}

friend int compute (sample e1);

};

int compute (sample e1)

{

return int (e1.a + e1.b) - 5;

}

Main ( )

{

Sample e;

e.test( );

Cout < < compute(e);

}
A
205
B
300
C
295
D
error
Question 22

If a class C is derived from class B which is derived from class A, all though public inheritance, then a class C member function can access

A
protected and public data in C and B
B
protected and public data only C
C
private data in A and B
D
protected data in A and B
Question 23

In C++ operator, << operator is called as

A
an insertion operator or put to operator
B
an extraction operator or get from operator
C
an insertion operator or get from operator
D
None of the given options
Question 23 Explanation: 
In C++ operator, << operator is called as an an insertion operator or put to operator.
Question 24

Function overloading in C++ is

A
A group function with the same name
B
all have the same numbers and type of arguments
C
functions with same name and same numbers and same type of arguments
D
None of the given options
Question 24 Explanation: 
Function Overloading is defined as the process of having two or more function with the same name, but different in parameters is known as function overloading in C++. In function overloading, the function is redefined by using either different types of arguments or a different number of arguments.
Question 25

How constructor differ from destructor?

A
Constructors can be overloaded but destructors can’t be overloaded
B
Constructors can take arguments but destructor can’t
C
Constructors can be overloaded but destructors can’t be overloaded and Constructors can take arguments but destructor can’t
D
None of the given options
Question 25 Explanation: 
Constructors can be overloaded but destructors can’t be overloaded.
Destructors cant be overloaded because your code wouldn't have a clue about which destructor it needs to call when you destroy an object.
Question 26

Abstract class cannot have

A
zero instance
B
multiple instance
C
Both zero instance and multiple instance
D
None of the given options
Question 27

Usually a pure virtual function

A
has complete function body
B
will never be called
C
will be called only to delete an object
D
is defined only in derived class
Question 28

If x=5, y=2, then x^y equals (where, ^ is a bitwise XOR operator)

A
00000111
B
10000010
C
10100000
D
11001000
Question 28 Explanation: 
In XOR,
1 XOR 1 = 0
1 XOR 0 =1
0 XOR 0 = 0
0 XOR 1 = 1
So 5 in binary form is 00000101 and 2 in binary form is 00000010.
Hence 00000101 XOR 00000010 = 00000111.
Question 29

Run-time polymorphism is achieved by

A
friend function
B
virtual function
C
operator overloading
D
function overloading
Question 29 Explanation: 
Run-time polymorphism is achieved by function overriding.
Question 30

The operator that cannot be overloaded is

A
++
B
::
C
0
D
~
Question 30 Explanation: 
There are 4 operators that cannot be overloaded in C++. They are :: (scope resolution), . (member selection), . * (member selection through pointer to function) and ?: (ternary operator).
Question 31

The keyword friend does not appear in

A
the class allowing access to another class
B
the class desiring access to another class
C
the private section of a class
D
the public section of a class
Question 32

The C++ statement cout <<(0 ==0) will

A
Outputs as 0
B
Outputs as 1
C
Generate error at the time of compilation
D
Generate run time
Question 32 Explanation: 
The above C++ statement outputs as 1.
Question 33

Which of the following statements is true about C++ language?

A
C++ supports multiple inheritance
B
C++ does not support operator overloading.
C
C++ supports dynamic polymorphism
D
C++ supports interface definitions.
E
Both A and D
Question 33 Explanation: 
C++ supports multiple inheritance.
C++ supports operator overloading.
C++ supports static polymorphism.
C++ supports interface definitions.
Question 34
Friend functions have access to
A
Private and protected members
B
Public members only
C
Private members only
D
None
Question 34 Explanation: 
A friend function of a class is defined outside that class' scope but it has the right to access all private and protected members of the class.
Question 35
Which of the following supports the concept of multiple inheritance?
A
C++
B
Java
C
Both C++ and Java
D
None
Question 35 Explanation: 
C++ supports multiple inheritance whereas java does not.
Question 36
Which of the following C++ statements correctly declares an abstract class?
A
Class A {virtual void show() = 0; };
B
Class A {void show() = 0;};
C
Class A {void show() { } ; };
D
Class A {show() = 0; };
Question 37
Which of the following are TRUE about constructions in C++ ?
(A)A constructor can be overloaded.
(B)A constructor does not have a return type.
(C)A constructor must be declared as a friend function.
(D)A constructor is called when an object is destroyed.
Choose the correct answer from the options green
A
(B), (C), (D) only
B
(B), (C) only
C
(A),(B), (C) only
D
(A),(B) Only
Question 38
What is the output of the code given below :
#include
Using namespace std;
class Base {
public:
Base(){
cout<<”Base const”;
}
Virtual ~Base()
{
cout<<”Base dest”;
}
};
class derived : public Base{
public:
Derived (){
cout<<”Derived Const”;
}
~ Derived(){
cout<< “Derived dest”;
}
};
int main ()
{
Base *b = new Derived ();
delete b;
return 0;
}
A
Base Const Derived Const Derived dest Base dest
B
Base Const Derived Const Base dest Derived dest
C
Derived Const Base Const Base dest Derived dest
D
Base Const Derived Const Base dest
Question 39
A three dimensional array in C++ is declared as int A[a][b][c].consider that array elements are stored in row major order and indexing begin from 0.Here the address of an item at the location A[r][s][t] computed in terms of word length w of an integer is
A
&A[0][0][0]+w(b*c*s+c*r+t)
B
&A[0][0][0]+w(b*c*r*+c*s+t)
C
&A[0][0][0]+w(a*b*r*+c*s+t)
D
&A[0][0][0]+w(a*b*s+c*r+t)
Question 39 Explanation: 
To compute the address of an item at the location A[r][s][t] in a three-dimensional array stored in row-major order as follows &A[0][0][0] + w * (b * c * r + c * s + t)
Question 40
If a constructor 'Date' is declared explicitly and has to be defined outside the class, which of the following is correct?
A
Date::Date(int dd) {/*...*/}
B
explicit Date::Date(int dd) {/*...*/}
C
Such a constructor cannot be defined
D
Constructor always has to be defined inside the class
Question 40 Explanation: 
Defining a Constructor Outside of the Class :Although the constructor can be defined outside of the class, it must be declared inside class. Use the scope resolution operator while defining a constructor outside of the class.
class class_name {
public:
class_name();
};

// Defining a Constructor Outside of the Class by using :: operator
class_name::class_name()
{
}
Question 41
Match List I with List II:
List I                                                             List II
(A) Localization                                        (I) Encapsulation
(B) Packaging or binding of a collection of items (II) Abstraction
(C) Mechanism that enables designer to focus on essential details of a program component (III) Characteristics of software that indicate the manner in which information is concentrated in a program.
(D) Information hiding                                           (IV) Suppressing the operational details of a program component
Choose the correct answer from the options given below:
A
(A)-(I), (B)-(II), (C)-(III), (D)-(IV)
B
(A)-(II), (B)-(I), (C)-(III), (D)-(IV)
C
(A)-(III), (B)-(I), (C)-(II), (D)-(IV)
D
(A)-(III), (B)-(I), (C)-(IV), (D)-(II)
Question 42
Which of the following are two main types of overloading in Java?
A
Overloading and linking
B
Overriding and linking
C
Reusability and data-hiding
D
Overloading and Overriding
Question 42 Explanation: 
Overloading occurs when two or more methods in one class have the same method name but different parameters.
Overriding occurs when two methods have the same method name and parameters. One of the methods is in the parent class, and the other is in the child class. Overriding allows a child class to provide the specific implementation of a method that is already present in its parent class.​
Question 43
During exception handling, which of the following statements hold true?
A
Single try can have multiple associated catch with it
B
A Single Catch can have multiple try associated with it
C
Finally block execute only when the class is inherited
D
For a given exception, multiple catch can execute
Question 44
In the given Program:
class Dialog1
{
public static void main(String args[])
{
Frame f1=new Frame("INDIA");
f1.setSize(300,300);
f1.setVisible(true);
FileDialog d=new FileDialog(f1, "MyDialog");
d.setVisible(true);
String fname=d.getDirectory()+d.getFile();
System.out.println("The Selection is"+fname);
}
}
To make the Frame visible, which of the following statements are true?
A
f1.setClear(true);
B
f1.setVisible(true);
C
f1.setlook(true);
D
f1.setclean(true);
Question 45
In Java, for ensuring the persistence property, the class must implements:
A
Serializable Interface
B
Utilization Interface
C
Threadable Interface
D
Recognizable Interface
Question 46
The static keyword word is used in public static void main() declaration in java:
A
To enable the JVM to make call to the main( ), as class has not been instantiated.
B
To enable the JVM to make call to the main( ), as class has not been inherited.
C
To enable the JVM to make call to the main( ), as class has not been loaded.
D
To enable the JVM to make call to the main( ), as class has not been finalized.
Question 47
In Java, when we implement an interface method, it must be declared as:
A
Private
B
Protected
C
Public
D
Friend
Question 48
Which one of the following is correct?
A
Java applets can not be written in any programming language
B
An applet is not a small program
C
An applet can be run on its own
D
Applets are embedded in another applications
Question 49
Which of the following operators cannot be overloaded in C/C++ ?
A
Bitwise right shift assignment
B
Address of
C
Indirection
D
Structure reference
Question 49 Explanation: 
→ We can’t overload structure reference in C and C++.
→ Bitwise right shift assignment(>>), Address of(&) and Indirection(*) can be overloaded in C and C++.
→ The . (dot) operator and the → (arrow) operator are used to reference individual members of classes, structures, and unions.
Question 50
Which of the following cannot be passed to a function in C++ ?
A
Constant
B
Structure
C
Array
D
Header file
Question 50 Explanation: 
→ Header files contain definitions of Functions and Variables, which is imported or used into any C++ program by using the pre-processor #include statement. Header file have an extension ".h" which contains C++ function declaration and macro definition.
→ Header file is a library file, we can not passed to a function in C++.
→ We can pass constant,Structure and Array
There are 50 questions to complete.

Access subject wise (1000+) question and answers by becoming as a solutions adda PRO SUBSCRIBER with Ad-Free content

Register Now