Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

RPSC Programmer Java DPP Part-4 By-Sunil Yadav Sir

Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

RPSC Programmer JAVA DPP Part-4 BY-SUNIL YADAV SIR 1

JAVA DPP Part - 4

final class Bus{


Q 1. What is the output of the below Java
program using Inheritance? void show() {
class A System.out.print("Generic Bus. "); }}
{
void call() class ElectricBus extends Bus{
{
void show(){
System.out.println("super called ");
} System.out.println("Electric Bus. "); }}
}
public class Inheritance4 {
class B extends A
{ public static void main(String[] args) {
void display()
{ ElectricBus eb = new ElectricBus();
System.out.println("sub called ");
eb.show();} }
}
} (a) Generic Bus (b) Electric Bus
class Main
(c)Generic Bus. Electric Bus.
{
public static void main(String a[]){ (d) Compiler error
A obj=new B();
obj.display(); Q 4. In a Multi-Level Inheritance in Java, the last
} subclass inheritsmethods and properties of ____.
} (a) Only one immediate Superclass
(a) super called (b) sub called (b) Few classes above it.
(c) All classes above it
(c)compilation error (d) None of the above

(d) runtime exception Q 5. What is the output of this program?

Q 2. To stop or block inheriting a given class, the class A


___ keyword is used before the class.
{
(a) Static (b) private
int i;
(c)final (d) None of the above
public void display() {

Q 3. What is the output of the below Java System.out.println(i); } }


program? class B extends A

Join RPSC Programmer Offline/Online Batch Contact @ 9694473047


RPSC Programmer JAVA DPP Part-4 BY-SUNIL YADAV SIR 2

{ int j; {

public void display() B obj = new B();

{System.out.println(j);} } obj.i=1;

class Dynamic_dispatch obj.j=2;

{ obj.display();

public static void main(String args[]) }}

{ (a) 1 2 (b) 2 1

B obj2 = new B(); (c)1 3 (d) 3 1

obj2.i = 1; Q 7. What is the output of this program?

obj2.j = 2; class Alligator

A r; {

r = obj2; public static void main(String[] args)

r.display(); } } {

(a) 1 (b) 2 int []x[] = {{1,2}, {3,4,5}, {6,7,8,9}};

(c)compilation error (d) 3 int [][]y = x;

Q 6. What is the output of this program? System.out.println(y[2][1]);

class A }}

{ public int i; (a) 2 (b) 3

protected int j;} (c)7 (d) Compilation Error

class B extends A
Q 8. Using which of the following, multiple
{ int j;
inheritance in Java can be implemented?
void display() {
(a) Interfaces (b) Multithreading
super.j = 3;
(c)Protected methods (d)Private methods
System.out.println(i + " " + j) }}

class Output {

public static void main(String args[])

Join RPSC Programmer Offline/Online Batch Contact @ 9694473047


RPSC Programmer JAVA DPP Part-4 BY-SUNIL YADAV SIR 3

Q 9. All classes in Java are inherited from which {


class?
System.out.print("Hello" + " " + 1 / 0);
(a) java.lang.class
}
(b) java.class.inherited
(c) java.class.object catch(ArithmeticException e)
(d) java.lang.Object
{
Q 10. In order to restrict a variable of a class
from inheriting to subclass, how variable should System.out.print("World");
be declared?
}}}
(a) Protected (b) Private
(a) Hello (b) World
(c)Public (d) Static
(c)HelloWorld (d) Hello World
Q 11. Which of the following is used for
Q 15. Which of the following handles the
implementing inheritance through an interface?
exception when a catch is not used?
(a) Inherited (b) using
(a) finally (b) throw handler
(c)extends (d) implements
(c)default handler (d) java run time system
Q 12. Which of the following operators is used
Q 16. Which of the following should be true of
to generate instance of an exception which can
the object thrown by a thrown statement?
be thrown using throw?
(a) Should be assignable to String type
(a) thrown (b) alloc
(b) Should be assignable to Exception type
(c)malloc (d)new (c) Should be assignable to Throwable type
(d) Should be assignable to Error type
Q 13Which of the following is a super class of all
exception type classes? Q 17. What is the output of this program?

(a) Catchable (b) RuntimeExceptions class exception_handling

(c)String (d) Throwable {

Q 14. What is the output of this program? public static void main(String args[])

class exception_handling {

{ try

public static void main(String args[]) {

{ throw new NullPointerException ("Hello");

try }

Join RPSC Programmer Offline/Online Batch Contact @ 9694473047


RPSC Programmer JAVA DPP Part-4 BY-SUNIL YADAV SIR 4

catch(ArithmeticException e) {

{ System.out.print("World");

System.out.print("B"); }}}

}}} (a) Hello (b) World


(b) HelloWOrld (d) Compilation Error
(a) A (b) B

(c)Compilation Error
Q 20. Which of these methods return description
(d) Runtime Error
of an exception?
Q 18. Which of these statements is incorrect?
(a) getException()
(a) try block need not to be followed by (b) getMessage()
catch block (c) obtainDescription()
(b) try block can be followed by finally block (d) obtainException()
instead of catch block
(c) try can be followed by both catch and
finally block
(d) try need not to be followed by anything

Q 19What is the output of this program?

class Output

public static void main(String args[])

try

int a = 0;

int b = 5;

int c = a / b;

System.out.print("Hello");

catch(Exception e)

Join RPSC Programmer Offline/Online Batch Contact @ 9694473047

You might also like