Object oriented programming Java -2 || diplomachakhazana

diplomachakhazana



 JOIN US


Sr.noSelect Any Option
1 Object Oriented Programming Java MCQ Page 1
2 Object Oriented Programming Java MCQ Page 2
3 Object Oriented Programming Java MCQ Page 3
4 Object Oriented Programming Java MCQ Page 4

Object oriented programming Java

Which of this keyword must be used to inherit a class?
a) super
b) this
c) extent
d) extends

Answer: d


A class member declared protected becomes a member of subclass of which
type?

a) public member
b) private member
c) protected member
d) static member

Answer: b


Which of these is correct way of inheriting class A by class B?
a) class B + class A {}
b) class B inherits class A {}
c) class B extends A {}
d) class B extends class A {}

Answer: c


Which two classes use the Shape class correctly?

A. public
class
Circle
implements
Shape 

   {

    private
int
radius
;

   }

B. public
abstract
class
Circle
extends
Shape 

   {

    private
int
radius
;

   }

C. public
class
Circle
extends
Shape 

   {

   private
int
radius
;

   public
void
draw
();

   }

D. public
abstract
class
Circle
implements
Shape 

   {

    private
int
radius
;

    public
void
draw
();

   }

E. public
class
Circle
extends
Shape 

   {

    private
int
radius
;

    public
void
draw
()

    {

     /* code here */

    }

   }

F. public
abstract
class
Circle
implements
Shape 

   {

     private
int
radius
;

     public
void
draw
() 

     { 

      /* code here */ 

     }

   }

a)B,E
b)A,C
c)C,E
d)T,H

Answer: a

What will be the output of the following Java program?

  1.     class

  2.     {

  3.         int
    i
    ;

  4.         void
    display
    () 

  5.         {

  6.             System.out.println(i);

  7.         }

  8.     }    

  9.     class
    B
    extends

  10.     {

  11.         int
    j
    ;

  12.         void
    display
    () 

  13.         {

  14.             System.out.println(j);

  15.         }

  16.     }    

  17.     class
    inheritance_demo 

  18.     {

  19.         public
    static
    void
    main
    (String
    args
    [])

  20.         {

  21.             B
    obj
    =
    new
    B
    ();

  22.             obj.i=1;

  23.             obj.j=2;   

  24.             obj.display();     

  25.         }

  26.    }

a) 0
b) 1
c) 2
d) Compilation Error

Answer: c

What is not type of inheritance?
a) Single inheritance
b) Double inheritance
c) Hierarchical inheritance
d) Multiple inheritance

Answer: b

Using which of the following, multiple inheritance in Java can be
implemented?

a) Interfaces
b) Multithreading
c) Protected methods
d) Private methods

Answer: a

All classes in Java are inherited from which class?
a) java.lang.class
b) java.class.inherited
c) java.class.object
d) java.lang.Object

Answer: d

 In order to restrict a variable of a class from inheriting to
subclass, how variable should be declared?

a) Protected
b) Private
c) Public
d) Static

Answer: b

 If super class and subclass have same variable name, which keyword
should be used to use super class?

a) super
b) this
c) upper
d) classname

Answer: a

Static members are not inherited to subclass.
a) True
b) False

Answer: b

 Which of the following is used for implementing inheritance through
an interface?

a) inherited
b) using
c) extends
d) implements

Answer: d

Which of the following is used for implementing inheritance through
class?

a) inherited
b) using
c) extends
d) implements

Answer: c

What would be the result if a class extends two interfaces and both have a
method with same name and signature? Lets assume that the class is not
implementing that method.

a) Runtime error
b) Compile time error
c) Code runs successfully
d) First called method is executed successfully

Answer: b

Does Java support multiple level inheritance?
a) True
b) False

Answer: a

Which of these keywords are used to define an abstract class?
a) abst
b) abstract
c) Abstract
d) abstract class

Answer: b

Which of these is not abstract?
a) Thread
b) AbstractList
c) List
d) None of the Mentioned

Answer: a

 If a class inheriting an abstract class does not define all of its
function then it will be known as?

a) Abstract
b) A simple class
c) Static class
d) None of the mentioned

Answer: a

Which of these is not a correct statement?
a) Every class containing abstract method must be declared abstract
b) Abstract class defines only the structure of the class not its
implementation

c) Abstract class can be initiated by new operator
d) Abstract class can be inherited

Answer: c

Which of these packages contains abstract keyword?
a) java.lang
b) java.util
c) java.io
d) java.system

Answer: a

 What will be the output of the following Java code?

  1.     class

  2.     {

  3.         public
    int
    i
    ;

  4.         private
    int
    j
    ;

  5.     }    

  6.     class
    B
    extends

  7.     {

  8.         void
    display
    () 

  9.         {

  10.             super.j
    =
    super.i
    +
    1;

  11.             System.out.println(super.i
    +
    ” “
    +
    super.j);

  12.         }

  13.     }    

  14.     class
    inheritance 

  15.    {

  16.         public
    static
    void
    main
    (String
    args
    [])

  17.         {

  18.             B
    obj
    =
    new
    B
    ();

  19.             obj.i=1;

  20.             obj.j=2;   

  21.             obj.display();     

  22.         }

  23.    }

  1. 2 2
    b) 3 3
    c) Runtime Error
    d) Compilation Error

Answer: d



 

What will be the output of the following Java code?

  1.     class

  2.     {

  3.         int
    i
    ;

  4.         void
    display
    () 

  5.         {

  6.             System.out.println(i);

  7.         }

  8.     }    

  9.     class
    B
    extends

  10.     {

  11.         int
    j
    ;

  12.         void
    display
    () 

  13.         {

  14.             System.out.println(j);

  15.         }

  16.     }    

  17.     class
    method_overriding 

  18.     {

  19.         public
    static
    void
    main
    (String
    args
    [])

  20.         {

  21.             B
    obj
    =
    new
    B
    ();

  22.             obj.i=1;

  23.             obj.j=2;   

  24.             obj.display();     

  25.         }

  26.    }

a)0

b)1

c)2

d) Compilation Error

Answer: c

 What will be the output of the following Java code?

  1.     class

  2.     {

  3.         public
    int
    i
    ;

  4.         protected
    int
    j
    ;

  5.     }    

  6.     class
    B
    extends

  7.     {

  8.         int
    j
    ;

  9.         void
    display
    () 

  10.         {

  11.             super.j
    =
    3;

  12.             System.out.println(i +
    ” “
    +
    j
    );

  13.         }

  14.     }    

  15.     class
    Output 

  16.     {

  17.         public
    static
    void
    main
    (String
    args
    [])

  18.         {

  19.             B
    obj
    =
    new
    B
    ();

  20.             obj.i=1;

  21.             obj.j=2;   

  22.             obj.display();     

  23.         }

  24.    }

a)12
b)21
c)13
d) 3 1

Answer: a

 

POLYMORPHISM

Which of the following is not OOPS concept in Java?
a) Inheritance
b) Encapsulation
c) Polymorphism
d) Compilation

Answer: d

 

Which of the following is a type of polymorphism in Java?
a) Compile time polymorphism
b) Execution time polymorphism
c) Multiple polymorphism
d) Multilevel polymorphism

Answer: a

 

 When does method overloading is determined?
a) At run time
b) At compile time
c) At coding time
d) At execution time

Answer: b

 

When Overloading does not occur?
a) More than one method with same name but different method signature and
different number or type of parameters

b) More than one method with same name, same signature but different number
of signature

c) More than one method with same name, same signature, same number of
parameters but different type

d) More than one method with same name, same number of parameters and type
but different signature

Answer: d

 

Which concept of Java is a way of converting real world objects in terms of
class?

a) Polymorphism
b) Encapsulation
c) Abstraction
d) Inheritance

Answer: c

 

Which concept of Java is achieved by combining methods and attribute into a
class?

a) Encapsulation
b) Inheritance
c) Polymorphism
d) Abstraction

Answer: a

 

Method overriding is combination of inheritance and polymorphism?
a) True
b) false

Answer: a

 

 


diplomachakhazana

null

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top