Search Header Logo

Competitive Programming Lab Quiz- 4B

Authored by Chayapathi R

Used 7+ times

Competitive Programming Lab Quiz- 4B
AI

AI Actions

Add similar questions

Adjust reading levels

Convert to real-world scenario

Translate activity

More...

    Content View

    Student View

20 questions

Show all answers

1.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

public class Solution{

       public static void main(String[] args){

                     short x = 10;

                     x =  x * 5;

                     System.out.print(x);

       }

}

The code will print 50
The code will print 10

compilation Error

Generates Exception

2.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

public class Solution{

       public static void main(String[] args){

               int[]  x = {120, 200, 016};

               for(int i = 0; i < x.length; i++){

                        System.out.print(x[i] + “ “);

               }                  

       }

}

120 200 16
120 200 016
120 200 14

none

3.

MULTIPLE CHOICE QUESTION

20 sec • 1 pt

Identify the correct restriction on static methods.

  1. I. They must access only static data

  2. II. They can only call other static methods.

  3. III. They cannot refer to this or super.

I and II

II and III

Only III

All of the above

4.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

public class ArraysInJava

{

public static void main(String[] args)

{

int[] i = new int[-1];

i[1]=20;

System.out.println(i[1]);

}

}

This code will compile and run without any issues with the output 20

This code will throw an ArrayIndexOutOfBoundsException
This code will throw a NegativeArraySizeException
This code will throw a NullPointerException

5.

MULTIPLE CHOICE QUESTION

20 sec • 1 pt

Identify the corrected definition of a package.

 

A package is a collection of editing tools

A package is a collection of classes

A package is a collection of classes and interfaces

A package is a collection of interfaces

6.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

What will be the output of following Java code?

public class Main {

  public static void main(String arg[]) {

    int i;

    for (i = 1; i <= 12; i += 2) {

      if (i == 8) {

        System.out.println(i);

        break;

      }

    }

  }

}

8
1, 3, 5, 7, 9, 11
1, 3, 5, 7
No output

7.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

import java.util.Scanner;

 

class ThisKeyword {

  private int a = 4;

  private int b = 1;

 

  void getSum(int a, int b) {

    this.a = a;

    this.b = b;

    System.out.println(this.a + this.b);

  }

}

 

public class Main {

  public static void main(String args[]) {

    ThisKeyword T = new ThisKeyword();

    T.getSum(3, 5);

  }

}

The output will be 8
The output will be 5
The output will be 9
The output will be 7

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?