Search Header Logo

java 15-10-2023

Authored by DEVAKI AMIR

Computers

Professional Development

Used 2+ times

java 15-10-2023
AI

AI Actions

Add similar questions

Adjust reading levels

Convert to real-world scenario

Translate activity

More...

    Content View

    Student View

10 questions

Show all answers

1.

MULTIPLE CHOICE QUESTION

2 mins • 1 pt

public class Test

{

    public Test()

    {

        System.out.printf("1");

        new Test(10);

        System.out.printf("5");

    }

    public Test(int temp)

    {

        System.out.printf("2");

        new Test(10, 20);

        System.out.printf("4");

    }

    public Test(int data, int temp)

    {

        System.out.printf("3");

         

    }

     

    public static void main(String[] args)

    {

        Test obj = new Test();

         

    }

     

}

12345

Compilation error

15

Runtime error 

2.

MULTIPLE CHOICE QUESTION

3 mins • 1 pt

public class Outer

{

    private int data = 10;

      

    class Inner

    {

        private int data = 20;

        private int getData()

        {

            return data;

        }

        public void main(String[] args)

        {

            Inner inner = new Inner();

            System.out.println(inner.getData());

              

        }

    }

    private int getData()

    {

        return data;

    }

    public static void main(String[] args)

    {

        Outer outer = new Outer();

        Outer.Inner inner = outer.new Inner();

        System.out.printf("%d", outer.getData());

        inner.main(args);

    }

}

2010

1020

Compilation Error

None of these

3.

MULTIPLE CHOICE QUESTION

2 mins • 1 pt

class Derived 

{

    public void getDetails()

    {

        System.out.printf("Derived class ");

    }

}

  

public class Test extends Derived

{

    public void getDetails()

    {

        System.out.printf("Test class ");

        super.getDetails();

    }

    public static void main(String[] args)

    {

        Derived obj = new Test();

        obj.getDetails();

    }

}

Test class Derived class

Derived class Test class

Compilation error

Runtime error

4.

FILL IN THE BLANK QUESTION

2 mins • 1 pt

Predict the Output of the following code.
class Clidder 

{

    private final void flipper() 

    {

        System.out.println("Clidder");

    }

}

  

public class Clidlet extends Clidder 

{

    public final void flipper() 

    {

        System.out.println("Clidlet");

    }

    public static void main(String[] args) 

    {

        new Clidlet().flipper();

    }

}

5.

MULTIPLE CHOICE QUESTION

3 mins • 1 pt

class Grandparent 

{

    public void Print() 

    {

        System.out.println("Grandparent's Print()"); 

    } 

}

  

class Parent extends Grandparent 

{

    public void Print() 

    {

        System.out.println("Parent's Print()"); 

    } 

}

  

class Child extends Parent 

{

    public void Print()   

    {

        super.super.Print();

        System.out.println("Child's Print()"); 

    } 

}

  

public class Main 

{

    public static void main(String[] args) 

    {

        Child c = new Child();

        c.Print(); 

    }

}

Child's Print()

Parent's Print()

Grandparent's Print()

Compiler Error

Answer explanation

Error in in super.super.Print()
It is not allowed to do super.super. We can only access Grandparent’s members using Parent

6.

MULTIPLE CHOICE QUESTION

2 mins • 1 pt

public class Test

{

    private String function()

    {

        return ("GFG");

    }

    public final static String function(int data)

    {

        return ("GeeksforGeeks");

    }

    public static void main(String[] args)

    {

        Test obj = new Test();

        System.out.println(obj.function());   

    }

}

Compilation error 

Runtime error 

GFG 

None of these

7.

MULTIPLE CHOICE QUESTION

1 min • 1 pt

class Main {

 public static void main(String args[]){

    final int i;

    i = 20;

    i = 30;

    System.out.println(i);

 }

}

20

Compiler Error

Garbage value

30

Answer explanation

i is assigned a value twice. Final variables can be assigned values only one. Following is the compiler error “Main.java:5: error: variable i might already have been assigned”

Access all questions and much more by creating a free account

Create resources

Host any resource

Get auto-graded reports

Google

Continue with Google

Email

Continue with Email

Classlink

Continue with Classlink

Clever

Continue with Clever

or continue with

Microsoft

Microsoft

Apple

Apple

Others

Others

Already have an account?