0

programming languages Online Quiz - 145

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

Which ALL are true?

  1. A finalizer may NOT be invoked explicitly.

  2. The finalize method declared in class Object takes no action

  3. super.finalize() is called implicitly by any overriding finalize method

  4. The finalize method for a given object will be called no more than once by the garbage collector

  5. The order in which finalize will be called on two objects is based on the order in which the two objects became finalizable


Correct Option: B,D

AI Explanation

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

A. A finalizer may NOT be invoked explicitly. - This option is incorrect because a finalizer can be invoked explicitly using the finalize() method. However, it is generally not recommended to do so.

B. The finalize method declared in class Object takes no action. - This option is correct. The finalize() method declared in the Object class does not perform any specific action. It is an empty method.

C. super.finalize() is called implicitly by any overriding finalize method. - This option is incorrect. The super.finalize() method is not called implicitly by any overriding finalize() method. It needs to be explicitly called if required.

D. The finalize method for a given object will be called no more than once by the garbage collector. - This option is correct. The finalize() method for a given object will be called by the garbage collector at most once. After the finalize() method is called, the object becomes eligible for garbage collection.

E. The order in which finalize will be called on two objects is based on the order in which the two objects became finalizable. - This option is not mentioned in the correct answer. Therefore, it is incorrect. The order in which the finalize() method is called on two objects is not determined by the order in which they became finalizable.

The correct answer is B, D. Option B is correct because the finalize() method declared in class Object takes no action. Option D is correct because the finalize() method for a given object will be called no more than once by the garbage collector.

String[] elements = { “for”, “tea”, “too” }; String first = (elements.length > 0)? elements[0] null; What is the result?

  1. Compilation fails.

  2. An exception is thrown at runtime

  3. The variable first is set to null.

  4. The variable first is set to elements[0].


Correct Option: D

AI Explanation

To answer this question, we need to understand the conditional (ternary) operator in Java.

The conditional operator (?:) has the following syntax:

(condition) ? expression1 : expression2

If the condition is true, expression1 is evaluated and becomes the result of the entire expression. If the condition is false, expression2 is evaluated and becomes the result.

In the given code snippet:

String first = (elements.length > 0) ? elements[0] : null;

The condition is "elements.length > 0", which checks if the length of the array "elements" is greater than 0.

If the condition is true (i.e., the array has at least one element), the expression "elements[0]" is evaluated and assigned to the variable "first". So, the variable "first" is set to the value of the first element in the array.

If the condition is false (i.e., the array is empty), the expression "null" is evaluated and assigned to the variable "first". So, the variable "first" is set to null.

Therefore, the correct answer is:

D. The variable first is set to elements[0].

Given: 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, we need to understand the syntax and behavior of the System.out.format() method.

In the given code snippet, System.out.format() is used to format output to the console. The format string "Pi is approximately %d." contains a placeholder %d, which is used to specify that a decimal integer value will be inserted at that position in the output.

However, the Math.PI constant in Java is a double value, not an integer. Therefore, when attempting to format the output using %d, a runtime exception will be thrown.

So, the correct answer is:

D. An exception is thrown at runtime

Variables are not interpolated inside which operator when used normally?

  1. " "

  2. < >

  3. ' '

  4. / /


Correct Option: C

Which of the following statements are correct when using the RETAINstatement?

  1. Variables read with the SET statement will not be affected by it

  2. The RETAIN statement is used when a variable needs to be

  3. Variables will be initialized to the desired value in each iteration

  4. Variables are created during execution


Correct Option: A

x='Hello' y=transwrd(x,'He','HiHiHe') what is the length of y?

  1. 200

  2. 9

  3. 5

  4. 10


Correct Option: A

What is true about ERROR statement

  1. It will be initialised to 1 in the begining

  2. It will have the observation number that caused the error

  3. It will not be dropped while writing into the dataset

  4. It can be used in expressions


Correct Option: D

p = 5461;x='1001';a=x ||'/'||pWhat is the value of a?

  1. 1001/ 5461

  2. Error because of concatenating character and numeric variable

  3. 1001/ 5461

  4. 1001/5461


Correct Option: C

data test; input @1 sal 6.; datalines; $1,234 ; run; What is the value of sal in the test dataset?

  1. Error because of giving formats while the format statement is not provided

  2. Missing

  3. 1234

  4. $1,234


Correct Option: B

Which of the following when evaluated are false?

  1. 1 and 4

  2. 2 and 4

  3. 3 and 1

  4. 2 and 3


Correct Option: A

how many elements are assigned to @u,@w?

  1. 1 and 2

  2. 5 and 0

  3. 1 and 3

  4. none of the above


Correct Option: B

What happens when @_ is modified?

  1. when arrays and references are passed

  2. only when references are passed

  3. args are not changed

  4. Command line args are changed


Correct Option: D

what is the output for printf ("%06.2f", $amt) when $amt = 9.355 ?

  1. 9.3550

  2. 9.4

  3. 009.40

  4. Error


Correct Option: C

What is the outcome of the scenario : open(FH, ">c:\temp\notes.txt") ?

  1. Opens a file notes.txt

  2. fails to create a file and displays error

  3. fails to open a file but doesn't display error

  4. Opens a file but not notes.txt


Correct Option: D

the regex /g.d?c*/ doesn't matches

  1. godccc

  2. gddd

  3. goc

  4. gc


Correct Option: B

which is correct?

  1. 1 can only be called with predecleration of complex_num

  2. 1 and 2 are same

  3. 2 can only be called with predecleration of complex_num

  4. 1 is reference to a subroutine


Correct Option: C

what does the structure create?

  1. A list of hashes which contains a list

  2. A hash of hashes which contains a list

  3. A list of list which contains another list

  4. A list of arrays and hashes containing lists


Correct Option: A

XML Schema is developed by?

  1. World Wide Web Consortium

  2. SWIFT

  3. Sun

  4. SAP


Correct Option: A

How many primitive data types does XSD provide?

  1. 4

  2. 8

  3. 10

  4. 19


Correct Option: D

What is the root element in XSD?


Correct Option: A
- Hide questions