github

Made bySaurav Hathi

MCQ Test Java: Object Oriented Programming 3

Q1:

/* Missing statements ? */

public class NewTreeSet extends java.util.TreeSet

{

    public static void main(String [] args)

    {

        java.util.TreeSet t = new java.util.TreeSet();

        t.clear();

    }

    public void clear()

    {

        TreeMap m = new TreeMap();

        m.clear();

    }

}

Which of the following statements when added at beginning of the program will allow the code to compile successfully?

1. No statement is required

2. import java.util.*;

3. import java.util.Tree;

4. import java.util.TreeSet;

5. import java.util.TreeMap;

Tags:
Section:
Core Programming
Options:
Q2:

What will be the output of this java program?

public class Test

{

    public int aMethod()

    {

        static int i = 0;

        i++;

        return i;

    }

    public static void main(String args[])

    {

        Test test = new Test();

        test.aMethod();

        int j = test.aMethod();

        System.out.println(j);

    }

}

Tags:
Section:
Core Programming
Options:
Q3:

What will be the output of this java program?

interface Count

{

    short counter = 0;

    void countUp();

}

public class TestCount implements Count

{

    public static void main(String [] args)

    {

        TestCount t = new TestCount();

        t.countUp();

    }

    public void countUp()

    {

        for (int x = 6; x>counter; x--, ++counter) /* Line 14 */

        {

            System.out.print(" " + counter);

        }

    }

}

Tags:
Section:
Core Programming
Options:
Q4:

Which of the following is not an OOPs concept?

Tags:
Section:
Core Programming
Options:
Q5:

Which of the following is a type of polymorphism in Java?

Tags:
Section:
Core Programming
Options:
Q6:

When is method overloading determined in java?

Tags:
Section:
Core Programming
Options:
Q7:

In which of the following cases, method overloading does not happen in java?

Tags:
Section:
Core Programming
Options:
Q8:

Which concept of OOPs is achieved by combining methods and attributes into a class?

Tags:
Section:
Core Programming
Options:
Q9:

What will be the output of this java program?

class PassA

{

public static void main(String [] args)

{

PassA p = new PassA();

p.start();

}

void start()

{

long [] a1 = {3,4,5};

long [] a2 = fix(a1);

System.out.print(a1[0] + a1[1] + a1[2] + " ");

System.out.println(a2[0] + a2[1] + a2[2]);

}

long [] fix(long [] a3)

{

a3[1] = 7;

return a3;

}

}

Tags:
Section:
Core Programming
Options:
Q10:

What will be the output of this java program?

class A

{

void A() /* Line 3 */

{

System.out.println("Class A");

}

public static void main(String[] args)

{

new A();

}

}

Tags:
Section:
Core Programming
Options:
Q11:

What will be the output of this java program?

class Base

{

Base()

{

System.out.print("Base");

}

}

public class Alpha extends Base

{

public static void main(String[] args)

{

new Alpha(); /* Line 12 */

new Base(); /* Line 13 */

}

}

Tags:
Section:
Core Programming
Options:
Q12:

What will be the output of the below java program?

class box

{

int width;

int height;

int length;

}

class mainclass

{

public static void main(String args[ ])

{

box obj1 = new box();

box obj2 = new box();

obj1.height = 1;

obj1.length = 2;

obj1.width = 1;

obj2 = obj1;

System.out.println(obj2.height);

}

}

Tags:
Section:
Core Programming
Options:
Q13:

What will be the output of the below java program?

class access

{

public int x;

static int y;

void cal(int a, int b)

{

x +=  a ;

y +=  b;

}

}

class static_specifier

{

public static void main(String args[ ])

{

access obj1 = new access();

access obj2 = new access();

obj1.x = 0;

obj1.y = 0;

obj1.cal(1, 2);

obj2.x = 0;

obj2.cal(2, 3);

System.out.println(obj1.x + " " + obj2.y);

}

}

Tags:
Section:
Core Programming
Options:
Q14:

What will be the output of this java program?

class access

{

static int x;

void increment()

{

x++;

}  

}  

class static_use

{

public static void main(String args[])

{

access obj1 = new access();

access obj2 = new access();

obj1.x = 0;  

obj1.increment();

obj2.increment();

System.out.println(obj1.x + " " + obj2.x);

}

}

Tags:
Section:
Core Programming
Options:
Q15:

At line number 2 below, choose 3 valid attributes/qualifiers among “final, static, native, public, private, abstract, protected”

public interface Status

{

       /* insert qualifier here */ int MY_VALUE = 10;

}

Tags:
Section:
Core Programming
Options:
Q16:

What will be the output of this java program?

class Alligator

{

    public static void main(String[] args)

    {

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

        int [][]y = x;

        System.out.println(y[2][1]);

    }

}

Tags:
Section:
Core Programming
Options:
Q17:

What will be the output of this java program?

abstract class A

{

    int i;

    abstract void display();

}   

class B extends A

{

    int j;

    void display()

    {

        System.out.println(j);

    }

}   

class Abstract_demo

{

    public static void main(String args[])

    {

        B obj = new B();

        obj.j=2;

        obj.display();   

    }

}

Tags:
Section:
Core Programming
Options:
Q18:

What will be the output of this java program?

class A

{

    public int i;

    private int j;

}   

class B extends A

{

    void display()

    {

        super.j = super.i + 1;

        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();    

    }

}

Tags:
Section:
Core Programming
Options:
Q19:

What will be the output of this java program?

class A

{

    public int i;

    protected int j;

}   

class B extends A

{

    int j;

    void display()

    {

        super.j = 3;

        System.out.println(i + " " + j);

    }

}   

class Output

{

    public static void main(String args[])

    {

        B obj = new B();

        obj.i=1;

        obj.j=2;  

        obj.display();    

    }

}

Tags:
Section:
Core Programming
Options:
Q20:

What will be the output of the following java code?

class Boxer1

{

    Integer i;

    int x;

    public Boxer1(int y)

    {

        x = i+y;

        System.out.println(x);

    }

    public static void main(String[] args)

    {

        new Boxer1 (new Integer(4));

    }

}

Tags:
Section:
Core Programming
Options: