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
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 2 Explanation: 
An ADT does not specify how the data type is implemented.
Question 3
___________ 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 3 Explanation: 
Process class is a class which implement lower level business abstractions required to manage the business domain class.
Question 4
In Java, when we implement an interface method, it must be declared as:
A
Private
B
Protected
C
Public
D
Friend
Question 5
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 6
Which of the following supports the concept of multiple inheritance?
A
C++
B
Java
C
Both C++ and Java
D
None
Question 6 Explanation: 
C++ supports multiple inheritance whereas java does not.
Question 7
Friend functions have access to
A
Private and protected members
B
Public members only
C
Private members only
D
None
Question 7 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 8

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 8 Explanation: 
The above C++ statement outputs as 1.
Question 9
Which of the following statements is/are TRUE regarding JAVA ? (a) Constants that cannot be changed are declared using the ‘static’ keyword. (b) A class can only inherit one class but can implement multiple interfaces.
A
Only (a) is TRUE.
B
Only (b) is TRUE.
C
Both (a) and (b) are TRUE.
D
Neither (a) nor (b) are TRUE.
Question 9 Explanation: 
FALSE: Constants that cannot be changed are declared using the ‘static’ keyword.
TRUE: A class can only inherit one class but can implement multiple interfaces.
Question 10
What is the output of the following JAVA program ?
Class Test {
   public static void main(String[] args) {
       Test obj = new Test();
       obj.start();
   }
   void start() {
       String stra = ”do”;
           String strb = method(stra);
       System.out.print(“: ”+stra + strb);
   }
   String method(String stra) {
       stra = stra + ”good”;
       System.out.print(stra);
       return“ good”;
   }
}
A
dogood : dogoodgood
B
dogood : gooddogood
C
dogood : dodogood
D
dogood : dogood
Question 11
Which of the following is NOT a type of constructor
A
Copy constructor
B
Friend constructor
C
Default constructor
D
Parameterized constructor
Question 11 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 12
Which one of the following CAN NOT be a friend
A
function
B
class
C
object
D
operator function
Question 12 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 13
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 13 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 14
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 14 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 15
How many objects can be created in a single class?
A
1
B
2
C
3
D
as many as required
Question 15 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 16
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 16 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 17
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 17 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 18
“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 18 Explanation: 
“this” is a reference variable that refers to the current object of the class.
Question 19
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 20
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 20 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 21

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 21 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 22
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 23

Run-time polymorphism is achieved by

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

The operator that cannot be overloaded is

A
++
B
::
C
0
D
~
Question 24 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 25

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 26
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 26 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 27
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 28
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 29
In Java, for ensuring the persistence property, the class must implements:
A
Serializable Interface
B
Utilization Interface
C
Threadable Interface
D
Recognizable Interface
Question 30
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 31
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 32
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 32 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 33
If a function is friend of a class, which one of the following is wrong?
A
A function can only be declared a friend by a class itself.
B
Friend functions are not members of a class, they are associated with it.
C
Friend functions are members of a class.
D
It can have access to all members of the class, even private ones.
Question 33 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. Even though the prototypes for friend functions appear in the class definition, friends are not member functions.
TRUE: function can only be declared a friend by a class itself.
TRUE: Friend functions are not members of a class, they are associated with it.
FALSE:Friend functions are members of a class.
TRUE: It can have access to all members of the class, even private ones.
Question 34
Consider the following two statements:
(a) A publicly derived class is a subtype of its base class.
(b) Inheritance provides for code reuse.
A
Both the statements (a) and (b) are correct.
B
Neither of the statements (a) and (b) are correct
C
Statement (a) is correct and (b) is incorrect
D
Statement (a) is incorrect and (b) is correct.
Question 34 Explanation: 
→ A publicly derived class is a subtype of its base class.
→ Inheritance is defined as deriving new classes (sub classes) from existing ones (super class or base class) and forming them into a hierarchy of classes.
→ Inheritance allows programmers to create classes that are built upon existing classes, to specify a new implementation while maintaining the same behaviors (realizing an interface), to reuse code and to independently extend original software via public classes and interfaces.
Question 35
In C++, which system - provided function is called when no handler is provided to deal with an exception?
A
terminate( )
B
unexpected( )
C
abort( )
D
kill( )
Question 35 Explanation: 
In some cases, the exception handling mechanism fails and a call to void terminate() is made. This terminate() call occurs in any of the following situations:
The exception handling mechanism cannot find a handler for a thrown exception. The following cases are more specific:
1. During stack unwinding, a destructor throws an exception and that exception is not handled.
2. The expression that is thrown also throws an exception, and that exception is not handled.
3. The constructor or destructor of a nonlocal static object throws an exception, and the exception is not handled.
4. A function registered with atexit() throws an exception, and the exception is not handled. The following demonstrates this:
A throw expression without an operand tries to rethrow an exception, and no exception is presently being handled.
Question 36
Which one of the following is correct, when a class grants friend status to another class?
A
The member functions of the class generating friendship can access the members of the friend class.
B
All member functions of the class granted friendship have unrestricted access to the members of the class granting the friendship.
C
Class friendship is reciprocal to each other.
D
There is no such concept.
Question 36 Explanation: 
→ When a class grants friend status to another class all member functions of the class granted friendship have unrestricted access to the members of the class granting the friendship.
→ Although the entire second class must be a friend to the first class, you can select which functions in the first class will be friends of the second class.
Question 37
When a method in a subclass has the same name and type signatures as a method in the super class, then the method in the subclass _____ the method in the super class.
A
Overloads
B
Friendships
C
Inherits
D
Overrides
Question 37 Explanation: 
→ When a method in a subclass has the same name and type signatures as a method in the superclass, then the method in the subclass overrides the method in the superclass.
Question 38
Consider the following code segment in JAVA
switch(x)
{
default;
system.out.println(“Hello”);
}
Which of the following data types are acceptable for x?
A
Byte and char
B
Long and char
C
Char and float
D
Byte and float
Question 38 Explanation: 
The possible values are either integer constant or character constant.No other data type values are allowed.
Question 39
Which of the following are valid calls to math.max in java?
  1. Math.max(1,4)
  2. Math.max(2.3,5)
  3. Math.max(1,3,5,7)
  4. Math.max(-1.5,-2.8f)
A
A,b and d
B
B,c and d
C
A,b and c
D
C and d
Question 39 Explanation: 
→The java.lang.Math.max(int a, int b) returns the greater of two int values.
→We can find the greater of any two data types variables.
→Option C consists of four variables , So it is invalid.
Question 40
Which of the following is NOT true in C++?
A
Before a variable can be used, it must be declared
B
Variable are allocated values through the use of assignment statements
C
When a variable is declared, C++ allocates storage for the variable and puts an unknown value inside it.
D
We can use a variable even if it is not declared.
Question 40 Explanation: 
In the c++ (or) C programming language , in order to use the variables in the program we must declare the variables before using.
Question 41
Which of the following is NOT true in case of protected Inheritance in C++?
A
Each public member in the base class is protected in the derived class
B
Each protected member in the base class is protected in the derived class
C
Each private member in the base class is private in the derived class
D
Each private member in the base class is visible in the derived class
Question 41 Explanation: 
The following table shows the access to members permitted by each modifier.
Question 42
If a class C is derived from class B, which is derived from class A, all through public inheritance, then a class C member function can access
A
Protected and public data only in C and B
B
Protected and public data only in C
C
Private data in A and B
D
Protected data in A and B
Question 42 Explanation: 
The following table shows the access to members permitted by each modifier.
Question 43
Mechanism of deriving a class from another derived class is known as
A
Polymorphism
B
Single inheritance
C
Multilevel inheritance
D
Message passing
Question 43 Explanation: 
When a class is derived from a class which is also derived from another class, i.e. a class having more than one parent classes, such inheritance is called Multilevel Inheritance.
Question 44
Members of  class by default are
A
Public
B
Private
C
Protected
D
Mandatory to specify
Question 44 Explanation: 
→A class in C++ is a user defined type or data structure declared with keyword class that has data and functions (also called methods) as its members whose access is governed by the three access specifiers private, protected or public (by default access to members of a class is private).
→The private members are not accessible outside the class; they can be accessed only through methods of the class. The public members form an interface to the class and are accessible outside the class.
Question 45
The memory occupied by an object type of data in VB is
A
1 byte
B
2 byte
C
4 byte
D
8 byte
Question 45 Explanation: 

Question 46
Given a class named student, which of the following is a valid constructor declaration for the class?
A
Student student(){}
B
Private final student(){}
C
Student(student s){}
D
Void student(){}
Question 46 Explanation: 
A constructor cannot specify any return type, not even void. A constructor cannot be final, static or abstract.
Question 47
Object oriented inheritance models:
A
"is a kind of" relationship
B
"has a" relationship
C
"want to be" relationship
D
"contains" of relationship
Question 47 Explanation: 
Generalization--> "is a kind of" relationship. It is used for object oriented inheritance models.
Aggregation-->"Has a" relationship
Question 48

What is the output of the following JAVA program ?

class simple 
{ 
     public static void main(String[] args) 
     { 
          simple obj = new simple(); 
          obj.start();
     } 
     void start()
     {
          long [] P = {3, 4, 5}; 
          long [] Q = method (P); 
          System.out.print (P[0] + P[1] + P[2]+”:”); 
          System.out.print (Q[0] + Q[1] + Q[2]); 
     }
     long [] method (long [] R) 
     { 
          R [1] = 7; return R; 
     }
} //end of class
A
12 : 15
B
15 : 12
C
12 : 12
D
15 : 15
Question 48 Explanation: 
• First we will create the object of simple class.
• By using object , we call the function start( ).
• In the start() function definition, first statement is integer array with three elements.
• long [ ] Q= method (P); Again function method(p) will be called.
• In the definition of method function, we are changing the second element of array to value 7 and returning updated array to array Q.
• We are passing address of P as argument to method so Modifications happened in the method automatically reflects to array P.
• Both array P and Q consists of values {3,7,5}.
• The sum of the three values are 15.
Question 49

In Java, which of the following statements is/are True ?

    S1 : The ‘final’ keyword applied to a class definition prevents the class from being extended through derivation.
    S2 : A class can only inherit one class but can implement multiple interfaces.
    S3 : Java permits a class to replace the implementation of a method that it has inherited. It is called method overloading.
Code :
A
S1 and S2 only
B
S1 and S3 only
C
S2 and S3 only
D
All of S1, S2 and S3
Question 49 Explanation: 
• If a class has multiple methods having same name but different in parameters, it is known as Method Overloading.Method Overloading is a feature that allows a class to have more than one method having the same name, if their argument lists are different. So the option-3 is False.
• The final keyword in java is used to restrict the user. The java final keyword can be used in many context. Final can be: variable, method and class.
• A Java class can only extend one parent class. Multiple inheritance (extends) is not allowed. Interfaces are not classes. However, and a class can implement more than one interface.
Question 50

Which of the following statements is/are True ?

P : C programming language has a weak type system with static types. Q : Java programming language has a strong type system with static types. Code :
A
P only
B
Q only
C
Both P and Q
D
Neither P nor Q
Question 50 Explanation: 
→ A strongly typed language has stricter typing rules at compile time, which implies that errors and exceptions are more likely to happen during compilation. Most of these rules affect variable assignment, return values and function calling.
→ A weakly typed language has looser typing rules and may produce unpredictable results or may perform implicit type conversion at runtime.
→ Java, C#, Ada and Pascal are sometimes said to be more strongly typed than C, a claim that is probably based on the fact that C supports more kinds of implicit conversions, and C also allows pointer values to be explicitly cast while Java and Pascal do not.
→ Java itself may be considered more strongly typed than Pascal as manners of evading the static type system in Java are controlled by the Java virtual machine's type system.
→ C# and VB.NET are similar to Java in that respect, though they allow disabling of dynamic type checking by explicitly putting code segments in an "unsafe context".
→ Pascal's type system has been described as "too strong", because the size of an array or string is part of its type, making some programming tasks very difficult.
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