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:
Online Test Series, Information About Examination,
Syllabus, Notification
and More.
Online Test Series, Information About Examination,
Syllabus, Notification
and More.