github

Made bySaurav Hathi

MCQ Test Java: Object Oriented Programming 2

Q1:

What will be the output of this java program ?

final class Complex {

    private final double re;

    private final double im;

 

    public Complex(double re, double im) {

        this.re = re;

        this.im = im;

    }

 

    public String toString() {

        return "(" + re + " + " + im + "i)";

    }

}

 

class Main {

  public static void main(String args[])

  {

       Complex c = new Complex(10, 15);

       System.out.println("Complex number is " + c);

  }        

}

Tags:
Section:
Core Programming
Options:
Q2:

What will be the output of below java code snippet?

   double a = 0.02;

   double b = 0.03;

   double c = b - a;

   System.out.println(c);

 

   BigDecimal _a = new BigDecimal("0.02");

   BigDecimal _b = new BigDecimal("0.03");

   BigDecimal _c = _b.subtract(_a);

   System.out.println(_c);

Tags:
Section:
Core Programming
Options:
Q3:

import java.awt.*;

class Ticker extends Component

{

    public static void main (String [] args)

    {

        Ticker t = new Ticker();

        /* Missing Statements ? */

    }

}

Which of the following statements could legally be inserted into missing section of this java code?

1. boolean test = (Component instanceof t);

2. boolean test = (t instanceof Ticker);

3. boolean test = t.instanceof(Ticker);

4. boolean test = (t instanceof Component);

Tags:
Section:
Core Programming
Options:
Q4:

What is the output of this java program?

class A

{

final public int calculate(int a, int b) { return 1; }

}

class B extends A

{

public int calculate(int a, int b) { return 2; }

}

public class output

{

public static void main(String args[])

{

B object = new B();

System.out.print("b is " + b.calculate(0, 1)); 

}

}

Tags:
Section:
Core Programming
Options:
Q5:

What is the output of this java program?

class c

{   

public void main( String[] args )

{ 

System.out.println( "Hello" + args[0] );

}

}

Tags:
Section:
Core Programming
Options:
Q6:

What is the output of this java program?

class access

{

public int x;

private int y;

void cal(int a, int b)

{

x =  a + 1;

y =  b;

}

}

class access_specifier

{

public static void main(String args[ ])

{

access obj = new access();

obj.cal(2, 3);

System.out.println(obj.x + " " + obj.y);

}

}

Tags:
Section:
Core Programming
Options:
Q7:

In java, which of these is the correct way of calling a parent class constructor having no parameters from a subclass?

Tags:
Section:
Core Programming
Options:
Q8:

In java, which of these methods of Object class is used to clone an object?

Tags:
Section:
Core Programming
Options:
Q9:

Which of these methods of Object class is used to obtain class of an object at run time in java?

Tags:
Section:
Core Programming
Options:
Q10:

Which of these is not abstract in java?

Tags:
Section:
Core Programming
Options:
Q11:

In java, if a class inheriting an abstract class does not define all of its methods then the class will be _________ .

Tags:
Section:
Core Programming
Options:
Q12:

Which of these is not a correct statement about java?

Tags:
Section:
Core Programming
Options:
Q13:

In java, class member declared protected becomes  _________  member of subclass.

Tags:
Section:
Core Programming
Options:
Q14:

Which of these is correct way of inheriting class A by class B in java ?

Tags:
Section:
Core Programming
Options:
Q15:

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 */

     }

   }

Tags:
Section:
Core Programming
Options:
Q16:

Which of these packages contain classes and interfaces used for input & output operations of a program?

Tags:
Section:
Core Programming
Options:
Q17:

Which of the following is true about inheritance in Java?

1) Private methods are final.

2) Protected members are accessible within a package and inherited classes outside the package.

3) Protected methods are final.

4) We cannot override private methods.

Tags:
Section:
Core Programming
Options:
Q18:

Which of the following is true about inheritance in Java?

1) In Java all classes inherit from the Object class directly or indirectly. The Object class is root of all classes.

2) Multiple inheritance is not allowed in Java.

3) Unlike C++, there is nothing like type of inheritance in Java where we can specify whether the inheritance is protected, public or private.

Tags:
Section:
Core Programming
Options:
Q19:

Which statement is true about java?

Tags:
Section:
Core Programming
Options:
Q20:

Which component is responsible to optimise byte code to machine code?

Tags:
Section:
Core Programming
Options:
Q21:

What would happen if constructor has a return type in java?

Tags:
Section:
Core Programming
Options:
Q22:

Abstract class cannot have a constructor in java.

Tags:
Section:
Core Programming
Options:
Q23:

In java, which of these operators can be used to check whether an object is an instance of a specified type?

Tags:
Section:
Core Programming
Options:
Q24:

In java, which of these access specifiers can be used for a class so that its members can be accessed by a different class in the same package?

Tags:
Section:
Core Programming
Options:
Q25:

In java, which of these access specifiers can be used for a class so that its members can be accessed by a different class in the different package?

Tags:
Section:
Core Programming
Options: