Object Oriented Programming CA2 QB For 2024-25
Object Oriented Programming CA2 QB For 2024-25
Q. No Question BTL
7 1
What will be the output of the following Java program?
classA
{
public int i;
public int j;
A()
{
i = 1;
j = 2;
}
}
classB extendsA
{
int i;
B()
{
i=3;
super();
}
}
class super_use
{
public static void main(String args[])
{
B obj = new B();
System.out.println(obj.i+""+ obj.j)
}
}
a) 1 2
b) 3 2
c) 1 3
d) Compilation Error
8 1
Which keyword is used to prevent a method from being overridden
in a subclass?
a) final
b) static
c) private
d) protected
Topic Name: Inheritance, Method,overloading, use of super keyword
9 1
Can a subclass inherit multiple classes in Java?
Q. No Question BTL
1 If a class inheriting an abstract class does not define all of its function then 1
it will be known as?
a) Abstract
b) A simple class
c) Static class
d) None of the mentioned
classA
{
public int i;
private int j;
}
classB extendsA
{
void display()
{
super.j= super.i *1+1;
super.i= 2;
System.out.println(super.i+""+ super.j);
}
}
class inheritance
{
public static void main(String args[])
{
B obj = new B();
obj.i=1;
obj.j=2;
obj.display();
}
}
a)22
b)33
c) Runtime Error
d) Compilation Error
7 1
Can an abstract class be instantiated (an object created)?
a) Yes, but only if it has concrete methods.
b) Yes, abstract classes can always be instantiated.
c) No, abstract classes cannot be instantiated directly.
d) Yes, but only if it's marked as static.
class Parent{
void show(){
System.out.println("Parent");
}
}
p.show();
c.show();
((Parent) c).show();
}
}
What will be the output of the program?
a) Parent
Child
Parent
b) Child
Child
Parent
c) Parent
Child
Child
d) Compilation Error
}
}
a) Compilation error in Line 1(abstract method cannot be private)
b) Compilation error in Line 2(abstract class cannot have concrete
method)
c) Compilation error in Line 3(abstract class cannot be extended)
d) Compilation error in Line 4(deposit method should have public access
modifier)
10 1
Bank(String bankName)
{
this.bankName = bankName;
}
office() {
super("Axis Bank");
}
}
A. Compilation error will occur because ""abstract class cannot have
constructor""
B. Compilation error will occur because ""abstract class must have an
abstract method""
C. Compilation error will occur while invoking the super class constructor
D. Code will be compiled successfully