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) - Identify whether the following statement is true or false. The finally block is executed when an exception is thrown, even if no catch matches it.

  1. True

  2. False


Correct Option: A

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

Reflection (introspection) is querying a class about its properties, and operating on methods and fields by the name for a given object instance. Why is reflection possible in the Java language?

  1. Late binding

  2. Early binding

  3. Java developers are very introspective people

  4. Reflection is possible in all languages


Correct Option: A

AI Explanation

To answer this question, you need to understand the concept of binding in programming languages.

Binding refers to the process of associating a method or function call with its corresponding implementation. There are two types of binding: early binding (static binding) and late binding (dynamic binding).

In Java, the default binding mechanism is early binding. Early binding refers to the process of binding a method call to its implementation at compile-time. This means that the compiler determines the method or function to be called based on the type of the object reference at compile-time.

However, Java also provides a mechanism called reflection that allows for late binding. Late binding refers to the process of determining the method or function to be called at runtime, based on the actual type of the object reference.

Using reflection, you can query a class about its properties, such as methods and fields, and operate on them by their name for a given object instance. This allows for dynamic invocation of methods and access to fields, even if they are not known at compile-time.

Therefore, the correct answer is:

A. Late binding - Reflection is possible in the Java language because it allows for late binding, enabling dynamic invocation of methods and access to fields at runtime.

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

Identify the correct examples of Exception

  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