0

programming languages Online Quiz - 209

Description: programming languages Online Quiz - 209
Number of Questions: 20
Created by:
Tags: programming languages
Attempted 0/20 Correct 0 Score 0

How long does the following code run? for(int x=0; x=3; x++)

  1. Never

  2. Three times

  3. Forever

  4. Error


Correct Option: C

Any class that implements the Runnable interface has to provide the implementation for the following methods public void start(); public void run();

  1. True

  2. False


Correct Option: A

What is the result of trying to compile and run the following code. public final static void main(String[] args){ double d = 10.0 / -0; if(d == Double.POSITIVE_INFINITY) System.out.println("Positive infinity"); else System.out.println("Negative infinity"); }

  1. output Positive infinity

  2. output Negative infinity

  3. Will fail to compile

  4. Runtime exception


Correct Option: A

What is the result that will be printed out ? void aMethod() { float f = (1 / 4) * 10; int i = Math.round(f); System.out.println(i); }

  1. 2

  2. 0

  3. 3

  4. 2.5


Correct Option: B

AI Explanation

To answer this question, let's go through the code step by step:

  1. float f = (1 / 4) * 10; In this line, the expression (1 / 4) performs integer division, which results in 0. The expression 0 * 10 evaluates to 0. Since the result is assigned to a float variable f, the value 0 is automatically converted to a float value of 0.0.

  2. int i = Math.round(f); The Math.round() method rounds the float value to the nearest integer. In this case, f is 0.0, which is already an integer value. So, the value of i will also be 0.

  3. System.out.println(i); Finally, the value of i which is 0 will be printed.

Therefore, the result that will be printed out is 0, which corresponds to option B.

What is the result that will be printed out ? void aMethod() { float f = (1 / 4) * 10; int i = Math.round(f); System.out.println(i); }

  1. Compiler error.

  2. Compiles and runs printing out 2

  3. Compiles and runs printing out 1

  4. An ArrayIndexOutOfBounds Exception at runtime


Correct Option: B

What will happen if you try to compile and run this ? public class Test{ static{ print(10); } static void print(int x){ System.out.println(x); System.exit(0); } }

  1. . Compiler error.

  2. Will throw a NoSuchMethod error at runtime.

  3. It will compile and run printing out "10"

  4. It will run with no output.


Correct Option: B

What is the value of d that will be printed out. public class Test { public final static void main(String[] args) { double d = - 22.22222; System.out.println(Math.ceil(d)); } }

  1. -23

  2. -22.0

  3. 22.0

  4. 24


Correct Option: B

ZZZ (Duplicate) - What is the output of the following, StringBuffer sb1 = new StringBuffer("Debopam"); StringBuffer sb2= new StringBuffer("Debopam "); String ss1 = " Debopam "; System.out.println(sb1==sb2); System.out.println(sb1.equals(sb2)); System.out.println(sb1.equals(ss1)); System.out.println("Poddar".substring(3));

  1. false false false dar

  2. false true false Poddar

  3. Compiler Error

  4. true true FALSE dar


Correct Option: A

Identify whether the following statement is true or false.
The keyword synchronized can be used with only a method

  1. True

  2. False


Correct Option: A

Identify whether the following statement is true or false.
The run () method should necessary exist in classes created as subclass of Thread

  1. True

  2. False


Correct Option: A

What is the purpose of the toolkit in the Abstract Window Toolkit (AWT)?

  1. To repair broken frames

  2. To create custom components

  3. An interface between the abstract window layer and windowing implementation

  4. To facilitate multicolor printing


Correct Option: C

What is an interface class?

  1. A collection of method declarations and constant values

  2. An abstract base class

  3. A way to get multiple inheritance

  4. A way to inherit variables and method implementations


Correct Option: A

Vertical and horizontal scroll bar increments are how many units by default?

  1. 12.5 units

  2. 100 units

  3. 5 units

  4. 1 unit


Correct Option: D

The StringBuffer class supports what type of strings?

  1. Mutable (changeable)

  2. Immutable (unchangeable)

  3. Violins and cellos

  4. Rotated and scaled


Correct Option: A

Why does an Assert class that checks program assertions need several implementations of its assert method?

  1. The Java language has loose type checking

  2. The Java language has tight type checking

  3. To keep tabs on garbage collection

  4. You never know how many you need, so you should always cover the most obvious cases


Correct Option: B

Handling an exception allows a program to terminate execution

  1. True

  2. False


Correct Option: B

Java's exception handling mechanism keeps error-processing code in the main line of a program's code to improve program clarity.

  1. True

  2. False


Correct Option: B
  1. Divide by zero error

  2. Accessing the elements of an array beyond its range

  3. Invalid input

  4. Opening an empty file

  5. Hard disk crash


Correct Option: A,B,C,E
- Hide questions