0

programming languages Online Quiz - 212

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

Given: class Alien { String invade(short ships) { return "a few"; } String invade(short... ships) { return "many"; } } class Defender { public static void main(String [] args) { System.out.println(new Alien().invade(7)); } } What is the result?

  1. many

  2. a few

  3. Compilation fails.

  4. An exception is thrown at runtim


Correct Option: C

AI Explanation

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

Option A) many - This option is incorrect because the invade method in the Alien class has two overloaded versions: one that takes a short parameter and one that takes a variable number of short parameters. In this case, the invade method is called with a single int argument (7), so it does not match any of the available methods.

Option B) a few - This option is incorrect for the same reason as option A. The invade method that takes a single short parameter is not called, so this option is not the result.

Option C) Compilation fails. - This option is correct because there is no matching method in the Alien class for the invade method call with an int argument. The compiler will give an error indicating that the method call is ambiguous because it matches both the method with a short parameter and the method with a variable number of short parameters.

Option D) An exception is thrown at runtime - This option is incorrect because the code fails to compile, so it will not even reach the runtime stage. Therefore, no exception will be thrown at runtime.

The correct answer is C. Compilation fails. This option is correct because the method call does not match any of the available methods in the Alien class.

Given: class Eggs { int doX(Long x, Long y) { return 1; } int doX(long... x) { return 2; } int doX(Integer x, Integer y) { return 3; } int doX(Number n, Number m) { return 4; } public static void main(String[] args) { new Eggs().go(); } void go () { short s = 7; System.out.print(doX(s,s) + " "); System.out.println(doX(7,7)); } } What is the result?

  1. 1 1

  2. 2 1

  3. 3 1

  4. 4 1

  5. 2 3

  6. 4 3


Correct Option: F

AI Explanation

To determine the result of the given code, let's go through each option and explain why it is correct or incorrect:

Option A) 1 1 - This option is incorrect. The doX() method is overloaded with different parameter types, but none of the overloads accept a short as an argument.

Option B) 2 1 - This option is incorrect. The doX() method is overloaded with different parameter types, but the doX(long... x) overload is not applicable for the given arguments because a short cannot be automatically promoted to a long.

Option C) 3 1 - This option is incorrect. The doX() method is overloaded with different parameter types, but the doX(Integer x, Integer y) overload is not applicable for the given arguments because a short cannot be automatically boxed to an Integer.

Option D) 4 1 - This option is incorrect. The doX() method is overloaded with different parameter types, but the doX(Number n, Number m) overload is not applicable for the given arguments because a short cannot be automatically boxed to a Number.

Option E) 2 3 - This option is incorrect. The doX() method is overloaded with different parameter types, but the doX(long... x) overload is not applicable for the given arguments because a short cannot be automatically promoted to a long. However, the doX(Integer x, Integer y) overload is applicable and will be chosen.

Option F) 4 3 - This option is correct. The doX() method is overloaded with different parameter types, and both the doX(Number n, Number m) overload and the doX(Integer x, Integer y) overload are applicable for the given arguments. However, the doX(Number n, Number m) overload is more specific because it accepts Number parameters, which are the superclasses of Integer. Therefore, it will be chosen for the call doX(s, s). The call doX(7, 7) will choose the doX(Integer x, Integer y) overload.

The correct answer is option F) 4 3.

Given: class Mixer { Mixer() { } Mixer(Mixer m) { ml = m;} Mixer m1; public static void main(String[] args) { Mixer m2 = new Mixer(); Mixer m3 = new Mixer(m2); m3.go(); Mixer m4 = m3.m1; m4.go(); Mixer m5 = m2.m1; m5.go(); } void go() { System.out.print("hi "); } } What is the result?

  1. hi

  2. hi hi

  3. hi hi hi

  4. Compilation fails

  5. hi, followed by an exception

  6. hi hi, followed by an exception


Correct Option: F

Given: 1. class Zippy { 2. String[] x; 3. int[] a [] = {{1,2}, {l}}; 4. Object c = new long [4] ; 5. Object[] d = x; 6. } What is the result?

  1. Compilation succeeds.

  2. Compilation fails due only to an error on line 3.

  3. Compilation fails due only to an error on line 4.

  4. Compilation fails due only to an error on line 5.

  5. Compilation fails due only to an error on line 3 and 5.

  6. Compilation fails due only to an error on line 3,4 and 5.


Correct Option: A

Given: class Fizz { int x = 5; public static void main(String[] args) { final Fizz f1 = new Fizz(); Fizz f2 = new Fizz(); Fizz f3 = FizzSwitch(f1,f2); System.out.println((f1 == f3) + " " + (f1.x == f3.x)); } static Fizz FizzSwitch(Fizz x, Fizz y) { final Fizz z = x; z.x = 6; return z; } } What is the result?

  1. true true

  2. true false

  3. false true

  4. false false

  5. Compilation fails.

  6. An exception is thrown at runtime.


Correct Option: A

AI Explanation

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

Option A) true true - This option is correct because it means that both the references f1 and f3 are pointing to the same object, and the value of x in that object is 6. So, (f1 == f3) is true because they refer to the same object and (f1.x == f3.x) is also true because the value of x is the same.

Option B) true false - This option is incorrect because (f1.x == f3.x) should be true since x is updated to 6 in the FizzSwitch method.

Option C) false true - This option is incorrect because (f1 == f3) should be true since f1 and f3 are referring to the same object.

Option D) false false - This option is incorrect because (f1 == f3) should be true since f1 and f3 are referring to the same object, and (f1.x == f3.x) should be true since x is updated to 6 in the FizzSwitch method.

Option E) Compilation fails - This option is incorrect because there are no compilation errors in the given code.

Option F) An exception is thrown at runtime - This option is incorrect because there are no exceptions thrown in the given code.

The correct answer is A. This option is correct because (f1 == f3) is true because they refer to the same object and (f1.x == f3.x) is also true because the value of x is the same.

Given: class Knowing { static final long tooth = 343L; static long doIt(long tooth) { System.out.print(++tooth + " "); return ++tooth; } public static void main(String[] args) { System.out.print(tooth + " "); final long tooth = 340L; new Knowing().doIt(tooth); System.out.println(tooth); } } What is the result?

  1. 343 340 340

  2. 343 340 342

  3. 343 341 342

  4. 343 341 340

  5. 343 341 343

  6. Compilation fails.


Correct Option: D

Given: 1. class Convert { 2. public static void main(String[] args) { 3. Long xL = new Long(456L); 4. long x1 = Long.valueOf("123"); 5. Long x2 = Long.valueOf("123"); 6. long x3 = xL.longValue(); 7. Long x4 = xL.longValue(); 8. Long x5 = Long.parseLong("456"); 9. long x6 = Long.parseLong("123"); 10. } 11. } Which will compile using Java 5, but will NOT compile using Java 1.4? (Choose all that apply.)

  1. Line 4

  2. Line 5

  3. Line 6

  4. Line 7

  5. Line 8

  6. Line 9


Correct Option: A,D,E

AI Explanation

To determine which lines will compile using Java 5 but not Java 1.4, let's analyze each line of code:

Line 4: long x1 = Long.valueOf("123"); This line will compile in both Java 5 and Java 1.4. The valueOf method returns a Long object, which can be assigned to a long variable.

Line 5: Long x2 = Long.valueOf("123"); This line will compile in both Java 5 and Java 1.4. Similar to line 4, the valueOf method returns a Long object, which can be assigned to a Long variable.

Line 6: long x3 = xL.longValue(); This line will compile in both Java 5 and Java 1.4. The longValue method returns a long value, which can be assigned to a long variable.

Line 7: Long x4 = xL.longValue(); This line will NOT compile in Java 1.4 but will compile in Java 5. In Java 1.4, the longValue method returns a long value, which cannot be directly assigned to a Long variable. In Java 5, it will automatically be boxed into a Long object.

Line 8: Long x5 = Long.parseLong("456"); This line will NOT compile in Java 1.4 but will compile in Java 5. In Java 1.4, the parseLong method returns a long value, which cannot be directly assigned to a Long variable. In Java 5, it will automatically be boxed into a Long object.

Line 9: long x6 = Long.parseLong("123"); This line will compile in both Java 5 and Java 1.4. The parseLong method returns a long value, which can be assigned to a long variable.

Based on the explanations above, the lines that will compile using Java 5 but will NOT compile using Java 1.4 are:

A. Line 4 D. Line 7 E. Line 8

Therefore, the correct answer is A, D, and E.

Given: 1. class Bigger { 2. public static void main(String[] args) { 3. // insert code here 4. } 5. } 6. class Better { 7. enum Faster {Higher, Longer}; 8. } Which, inserted independently at line 3, will compile? (Choose all that apply.)

  1. Faster f = Faster.Higher;

  2. Faster f = Better.Faster.Higher;

  3. Better.Faster f = Better.Faster.Higher;

  4. Bigger.Faster f = Bigger.Faster.Higher;

  5. Better. Faster f2; f2 = Better.Faster.Longer;

  6. Better b; b.Faster = f3; f3 = Better.Faster.Longer;


Correct Option: C,E

Given: class Bird { { System.out.print("bl "); } public Bird() { System.out.print("b2 "); } } class Raptor extends Bird { static { System.out.print("r1 "); } public Raptor() { System.out.print("r2 "); } { System.out.print("r3 "); } static { System.out.print("r4 "); } } class Hawk extends Raptor { public static void main(String[] args) { System.out.print("pre "); new Hawk(); System.out.println("hawk "); } } What is the result?

  1. pre b1 b2 r3 r2 hawk

  2. pre b2 b1 r2 r3 hawk

  3. pre b2 b1 r2 r3 hawk r1 r4

  4. r1 r4 pre b1 b2 r3 r2 hawk

  5. r1 r4 pre b2 b1 r2 r3 hawk

  6. Compilation fails.


Correct Option: D
  1. Check table will be at field level checking.

  2. Value table will be at domain level checking

  3. Value table will be at field level checking

  4. Check table will be at domain level checking


Correct Option: A,B
  1. Transparent tables

  2. Internal Table

  3. Pool tables

  4. Cluster tables


Correct Option: A,C,D

Is Session Method, Asynchronous or Synchronous?

  1. Asynchronous

  2. Synchronous

  3. Synchronous and Asynchronous

  4. None of above


Correct Option: B

Which data type cannot be used to define parameters?

  1. Type N

  2. Type C

  3. Type F

  4. Type P


Correct Option: C

Which Command flushes the database buffers?

  1. $TAB

  2. $RESET

  3. $INIT

  4. $FREE


Correct Option: A

AI Explanation

To answer this question, we need to understand the purpose of flushing database buffers and how it is done.

Database buffers are used to temporarily store data in memory before writing it to the disk. Flushing the database buffers involves writing the data from the buffers to the disk, ensuring that the data is persistent and not lost in case of a system failure.

Among the given options, the correct command to flush the database buffers is:

A) $TAB - This option is correct because the $TAB command is commonly used to flush the database buffers. It forces the data in the buffers to be written to the disk, ensuring data durability.

B) $RESET - This option is incorrect because the $RESET command is not typically used to flush database buffers. The $RESET command is usually used to reset system configurations or parameters.

C) $INIT - This option is incorrect because the $INIT command is not commonly used to flush database buffers. The $INIT command is typically used for initializing or starting a process or system.

D) $FREE - This option is incorrect because the $FREE command is not typically used to flush database buffers. The $FREE command is usually used to release memory or resources that are no longer needed.

The correct answer is A) $TAB. This option is correct because the $TAB command is commonly used to flush the database buffers and ensure data durability.

What is new in EJB 2.1 ?

  1. Message-driven beans (MDBs)

  2. EJB query language (EJB-QL)

  3. Support for Web services

  4. All of the Above

  5. Only 1 & 2

  6. Only 1 & 3


Correct Option: D
  1. Entity beans are permanent business entities

  2. Entity Beans are persistence objects

  3. EntityBeans are permanent

  4. All of the Above

  5. Only 1 & 2

  6. Only 1 & 3


Correct Option: D

JMS stands for .....

  1. Java Messaging Service

  2. Java Message Service

  3. Java Messenger Service

  4. Java Model Security


Correct Option: A

It is possible to maintain persistence temporarily in stateful sessionbeans?

  1. True

  2. False


Correct Option: A
- Hide questions