programming languages Online Quiz - 203

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

System.out.format("Pi is approximately %d.", Math.PI); What is the result?

  1. Compilation fails

  2. Pi is approximately 3

  3. Pi is approximately 3.141593

  4. An exception is thrown at runtime

Correct Option: D

AI Explanation

To answer this question, let's go through each option to understand why it is correct or incorrect:

Option A) Compilation fails - This option is incorrect. The given code snippet does not contain any syntax errors, so it will compile successfully.

Option B) Pi is approximately 3 - This option is incorrect. The code snippet uses the format specifier "%d" in the format string, which is used for integers. Since Math.PI is a double value, using "%d" would result in incorrect output.

Option C) Pi is approximately 3.141593 - This option is incorrect. The code snippet does not specify the precision or decimal places to be displayed. By default, the decimal places are limited, so the output would not display the full value of Math.PI.

Option D) An exception is thrown at runtime - This option is correct. The code snippet tries to format a double value using the format specifier "%d" which is used for integers. This will result in a runtime exception, specifically a java.util.IllegalFormatConversionException.

The correct answer is D. An exception is thrown at runtime because the format specifier (%d) used is incompatible with the type of value (double) being passed.

  1. Inheritance represents an is-a relationship

  2. . Inheritance represents a has-a relationship

  3. Interfaces must be used when creating a has-a relationship

  4. Instance variables can be used when creating a has-a relationship

Correct Option: A,D

public static void test(String str) { if (str == null | str.length() == 0) { System.out.println("String is empty"); } else { System.out.println("String is not empty"); } } And the invocation: test(null); What is the result?

  1. An exception is thrown at runtime.

  2. "String is empty" is printed to output

  3. Compilation fails

  4. "String is not empty" is printed to output.

Correct Option: A
  1. Compilation fails.

  2. An exception is thrown at runtime.

  3. The code executes normally and prints "sleep".

  4. The code executes normally, but nothing is print ed.

Correct Option: C

1 String #name = "Jane Doe"; 2 int $age = 24; 3 Double _height = 123.5; 4 double ~temp = 37.5; Which two statements are true?

  1. . Line 1 will not compile

  2. . Line 2 will not compile

  3. . Line 3 will not compile

  4. . Line 4 will not compile

Correct Option: A,D

The primary key on table EMP is the EMPNO column. Which of the following statements will not use the associated index on EMPNO?

  1. select * from EMP where nvl(EMPNO, '00000') = '59384';

  2. select * from EMP where EMPNO = '59384';

  3. select EMPNO, LASTNAME from EMP where EMPNO = '59384';

  4. select 1 from EMP where EMPNO = '59834';

Correct Option: A

Assuming today is Monday, 10 July 2000, what is returned by this statement: SELECT to_char(NEXT_DAY(sysdate, 'MONDAY'), 'DD-MON-RR') FROM dual;

  1. 03-JUL-00

  2. 10-JUL-00

  3. 11-JUL-00

  4. 17-JUL-00

Correct Option: D

Which character function can be used to return a specified portion of a character string?

  1. INSTR



  4. POS

Correct Option: C

This Contains all of the classes for creating user interfaces and for painting graphics and images

  1. java.lang

  2. java.util

  3. java.awt

  4. java.graphics

Correct Option: C

What does API stand for?

  1. Assignment Programming Interface

  2. Application Programming Interface

  3. Active Program Interface

  4. None of the above

Correct Option: B

Which API provides classes that are fundamental to the design of the Java programming language?

  1. Java.lang

  2. Java.nio

  3. Java.rmi

  4. Java.basic

Correct Option: A
  1. java.nio

  2. java.text

  3. java.xml

  4. java.io

Correct Option: C

Which of the following APIs provides the classes and interfaces for the security framework?

  1. java.io

  2. java.rmi

  3. java.security

  4. None of the above

Correct Option: C
  1. Combined Business-Oriented Language

  2. Combined Business-OnLine Language

  3. Common Business-Oriented Language

  4. Common Business online Language

Correct Option: C
  1. PICTURE clauses

  2. VALUE clauses

  3. 'TO' in the statements

  4. All COBOL verbs

Correct Option: D
- Hide questions