Let the boxes be $B_1, B_2, B_3$ and event $E$ be drawing $1$ white and $1$ red ball.
Since one box is chosen randomly,
$P(B_1)=P(B_2)=P(B_3)=\frac{1}{3}$
For first box,
$P(E|B_1)=\frac{\binom{2}{1}\binom{4}{1}}{\binom{9}{2}}=\frac{8}{36}=\frac{2}{9}$
For second box,
$P(E|B_2)=\frac{\binom{3}{1}\binom{2}{1}}{\binom{7}{2}}=\frac{6}{21}=\frac{2}{7}$
For third box,
$P(E|B_3)=\frac{\binom{4}{1}\binom{3}{1}}{\binom{8}{2}}=\frac{12}{28}=\frac{3}{7}$
Using Bayes theorem,
$P(B_1|E)=\frac{P(B_1)P(E|B_1)}{P(B_1)P(E|B_1)+P(B_2)P(E|B_2)+P(B_3)P(E|B_3)}$
$P(B_1|E)=\frac{\frac{1}{3}\times\frac{2}{9}}{\frac{1}{3}\times\frac{2}{9}+\frac{1}{3}\times\frac{2}{7}+\frac{1}{3}\times\frac{3}{7}}$
$P(B_1|E)=\frac{\frac{2}{9}}{\frac{2}{9}+\frac{2}{7}+\frac{3}{7}}$
$P(B_1|E)=\frac{\frac{2}{9}}{\frac{59}{63}}=\frac{14}{59}=0.237$
What is the output of the following JAVA program?
public class Good {
private int m;
public Good(int m) {
this.m = m;
}
public Boolean equals(Good n) {
return n.m == m;
}
public static void main(String args[]) {
Good m1 = new Good(22);
Good m2 = new Good(22);
Object s1 = new Good(22);
Object s2 = new Good(22);
System.out.println(m1.equals(m2));
System.out.println(s1.equals(s2));
System.out.println(m1.equals(s2));
System.out.println(s1.equals(m2));
}
Here, the class has a method
$equals(Good\ n)$
This method does not override the original $equals(Object)$ method of Java because the parameter type is $Good$, not $Object$.
For Line 1:
$m1.equals(m2)$
Here both are objects of class $Good$, so $equals(Good\ n)$ is called.
Both values are $22$, so output is
$True$
For Line 2:
$s1.equals(s2)$
Here $s1$ and $s2$ are declared as $Object$ type.
So, Java calls $Object$ class $equals()$ method, which compares references.
Since both are different objects, output is
$False$
For Line 3:
$m1.equals(s2)$
Here $s2$ is of type $Object$, so $equals(Good\ n)$ is not called.
It calls $equals(Object)$, so reference comparison is done.
Output is
$False$
For Line 4:
$s1.equals(m2)$
Here $s1$ is of type $Object$, so again $Object$ class $equals()$ method is called.
Output is
$False$
Therefore, output is:
$True,\ False,\ False,\ False$
Python → OOP
Smalltalk → pure OOP
Perl → supports OOP
SQL Plus → database query interface.
In protected inheritance:
Public members of base class become protected members in derived class.
Protected members of base class also remain protected in derived class.
Private members of base class are not directly accessible in derived class.
So, member functions of class $B$ can access public and protected members of class $A$.
But object of class $B$ cannot access public base class data directly, because it becomes protected after protected inheritance.
JVM executes Java bytecode.
For execution, JVM mainly needs:
Class loader to load the class files
Java Interpreter to interpret and execute bytecode
So, JVM needs class loader and Java interpreter.
| List-I | List-II |
|---|---|
| A. Localization | I. Encapsulation |
| B. Packaging or binding of a collection of items. | II. Abstraction |
| C. Mechanism that enables a designer to focus on essential details of a program component. | III. Characteristic of software that indicates in a manner which information is concentrated in the program. |
| D. Information hiding. | IV. Suppressing the operational details of a program component. |
Inheritance provides the benefits of
A. shared interfaces
B. run-time polymorphism
C. less redundant information
D. dynamic binding
Which of the following is correct using the constructor?
A. string s1;
B. string s2(s1);
C. string s3{7};
D. string s4{'a'};
E. string s5{7,'a'};
Choose the most appropriate answer from the
options given below:
Initial values
$a = 5,; b = 10$
First call
swap(a,b)
$a = 10,; b = 5$
Second call
swap(a,b)
$a = 5,; b = 10$
Thus final output
5 10
| List I | List II |
|---|---|
| A. JNDI | I. Runtime support for running Java program |
| B. RMI | II. The API in support of naming and directory services. |
| C. JDK | III. The methods provided by the Java development kit and runtime support for calling remote methods. |
| D. JRE | IV. The compiler and class libraries to develop Java applications. |
| List I | List II |
|---|---|
| A. Imperative | I. Declarative, clausal representation, theorem proving |
| B. Object-oriented | II. Side-effect-free, declarative, expression evaluation |
| C. Logic | III. Imperative, abstract data type |
| D. Functional | IV. Command-based, procedural |
Which of the following statements are true regarding C++?
(a) Overloading gives the capability 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 is executed then constructor of a base class is executed.
(d) Overloading is a type of polymorphism.
Choose the correct option from those given below:
Statement (a) is true.
Operator overloading allows an existing operator to work with user-defined or other data types.
Statement (b) is true.
Inheritance supports code reusability in object oriented programming.
Statement (c) is false.
When an object of derived class is created, the base class constructor is executed first, then derived class constructor is executed.
Statement (d) is true.
Overloading is a form of compile-time polymorphism.
So, correct statements are:
(a), (b) and (d)
(A) True
Constructors can be overloaded.
(B) True
Constructors do not have return type.
(C) False
Constructors are member functions, not friend functions.
(D) False
Destructor is called when object is destroyed.
Thus correct statements:
(A) and (B)
What is the output of code given below :
#include<iostream.h>
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;
}
Step-1: Object creation
Base *b = new Derived();
Constructor order in inheritance:
Base constructor
Derived constructor
Output:
Base Const
Derived Const
Step-2: Deleting object
Base destructor is virtual, so destructors call in reverse order:
Derived destructor
Base destructor
Output:
Derived dest
Base dest
Final Output:
Base Const Derived Const Derived dest Base dest
In C++, the keyword $\text{explicit}$ is used only while declaring the constructor inside the class.
When the constructor is defined outside the class, $\text{explicit}$ is not written again.
So, the correct definition is:
$ \text{Date::Date(int dd) { /* ... */ }} $
| List I | List II |
|---|---|
| A. Overloading | III. Supports compile-time polymorphism |
| B. Early Binding | II. Since function call is resolved during compilation time, the execution is much faster |
| C. Overriding | I. Since function call is resolved during run time, the execution is slow |
| D. Late Binding | IV. Supports run-time polymorphism |
Match the List-I and List-II
| List-I | List-II |
| a. If the implementation of generated or derived classes differs only through a parameter we have | I. to use class hierarchy |
| b. If the actual types of objects used cannot be known at compile time, then we have | II. improved run-time efficiency |
| c. If inline operations are essential and templates are used then we have | III. to use templates |
| d. To gain access to differing instances for derived classes through base we have | IV. to use explicit casting |
Choose the correct answer from the options given below:
For a:
If implementation differs only through a parameter, templates are useful.
So,
a → III
For b:
If actual object types are not known at compile time, class hierarchy and runtime polymorphism are used.
So,
b → I
For c:
Templates allow inline operations and can improve run-time efficiency.
So,
c → II
For d:
To access derived class instances through base class reference or pointer, explicit casting may be used.
So,
d → IV
Correct matching:
a-III, b-I, c-II, d-IV
Multiple Inheritance is permitted directly in:
A. C++
B. Java
C. Python
D. VB.NET
E. BASIC
C++ → supports multiple inheritance directly ✔
• Java → does not support multiple inheritance with classes (only interfaces) ✘
• Python → supports multiple inheritance ✔
• VB.NET → supports multiple inheritance through interfaces only ✘
• BASIC → does not support multiple inheritance ✘
Thus the languages that directly support multiple inheritance are:
C++ and Python
Online Test Series,
Information About Examination,
Syllabus, Notification
and More.
Online Test Series,
Information About Examination,
Syllabus, Notification
and More.