0

programming languages Online Quiz - 300

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

byte b; final int a = 10; final int x = a; b = x; System.out.println("The value of b is " + b);

  1. Compilation error

  2. Runtime Error

  3. 10

  4. None of these


Correct Option: C

Which one is not correct A. x = = Float.NaN B. Float.isNan(x); C. Myobject .equals(float.NaN);

  1. A

  2. B

  3. Both

  4. None of these


Correct Option: B

What will happen when you attempt to compile and run the following code? (Assume that the code is compiled and run with assertions enabled.) public class AssertTest { public void methodA(int i) { assert i >= 0 : methodB(); System.out.println(i); } public void methodB() { System.out.println("The value must not be negative"); } public static void main(String args[]) { AssertTest test = new AssertTest(); test.methodA(-10); } }

  1. It will print -10

  2. It will result in Assertion Error showing the message -"The value must not be negative".

  3. The code will not compile.

  4. None of these.


Correct Option: C

What will happen when you attempt to compile and run the following code? interface MyInterface { } public class MyInstanceTest implements MyInterface { static String s; public static void main(String args[]) { MyInstanceTest t = new MyInstanceTest(); if(t instanceof MyInterface) { System.out.println("I am true interface"); } else { System.out.println("I am false interface"); } if(s instanceof String) { System.out.println("I am true String"); } else { System.out.println("I am false String"); } } }

  1. Prints : "I am false interface" followed by " I am false String"

  2. Prints : "I am true interface" followed by " I am true String"

  3. Prints : "I am true interface" followed by " I am false String"

  4. Compile-time error


Correct Option: C

What results from attempting to compile and run the following code? public class Ternary { public static void main(String args[]) { int a = 5; System.out.println("Value is - " + ((a < 5) ? 9.9 : 9)); } }

  1. prints: Value is - 9

  2. prints: Value is - 5

  3. Compilation error

  4. None of these


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) prints: Value is - 9 - This option is incorrect. The code snippet will not print "Value is - 9" because the condition a &lt; 5 evaluates to false.

Option B) prints: Value is - 5 - This option is incorrect. The code snippet will not print "Value is - 5" because the condition a &lt; 5 evaluates to false.

Option C) Compilation error - This option is incorrect. The code snippet does not contain any syntax errors and will compile successfully.

Option D) None of these - This option is correct. The code snippet will print "Value is - 9" because the condition a &lt; 5 evaluates to false, and the value 9 is returned as the result of the ternary operator. The result is then concatenated with the string "Value is - " and printed to the console.

The correct answer is D. None of these.

What will happen when you attempt to compile and run the following code? class MyThread extends Thread { public void run() { System.out.println("MyThread: run()"); } public void start() { System.out.println("MyThread: start()"); } } class MyRunnable implements Runnable { public void run() { System.out.println("MyRunnable: run()"); } public void start() { System.out.println("MyRunnable: start()"); } } public class MyTest { public static void main(String args[]) { MyThread myThread = new MyThread(); MyRunnable myRunnable = new MyRunnable(); Thread thread = new Thread(myRunnable); myThread.start(); thread.start(); } }

  1. Prints : MyThread: start() followed by MyRunnable:run()

  2. Prints : MyThread: run() followed by MyRunnable:start()

  3. Prints : MyThread: start() followed by MyRunnable:start()

  4. Compile time error


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) Prints: MyThread: start() followed by MyRunnable: run() - This option is incorrect. The start() method of the MyThread class is overridden to print "MyThread: start()", but it does not start the thread. The run() method of the MyRunnable class is not overridden and it prints "MyRunnable: run()". Since both threads are called using the start() method, both will execute in parallel, and the order of execution is not guaranteed. So it is possible that the output could be "MyRunnable: run()" followed by "MyThread: start()".

Option B) Prints: MyThread: run() followed by MyRunnable: start() - This option is incorrect. As explained in Option A, the start() method of the MyThread class is overridden and does not start the thread. The run() method of the MyRunnable class is not overridden and it prints "MyRunnable: run()". Since both threads are called using the start() method, both will execute in parallel, and the order of execution is not guaranteed. So it is possible that the output could be "MyThread: run()" followed by "MyRunnable: start()".

Option C) Prints: MyThread: start() followed by MyRunnable: start() - This option is incorrect. As explained in Option A, the start() method of the MyThread class is overridden and does not start the thread. The run() method of the MyRunnable class is not overridden and it prints "MyRunnable: run()". Since both threads are called using the start() method, both will execute in parallel, and the order of execution is not guaranteed. So it is possible that the output could be "MyThread: start()" followed by "MyRunnable: start()".

Option D) Compile time error - This option is incorrect. The code will compile without any errors because there are no syntax errors or type mismatches.

The correct answer is A. This option is correct because the start() method of the MyThread class is overridden to print "MyThread: start()", and the run() method of the MyRunnable class is not overridden and it prints "MyRunnable: run()". Since both threads are called using the start() method, both will execute in parallel, and it is possible that the output could be "MyThread: start()" followed by "MyRunnable: run()".

What will happen when you attempt to compile and run the following code? public class Static { static { int x = 5; } static int x,y; public static void main(String args[]) { x--; myMethod(); System.out.println(x + y + ++x); } public static void myMethod() { y = x++ + ++x; } }

  1. Compile-time error

  2. prints : 3

  3. prints : 1

  4. prints : 7


Correct Option: B

What will happen when you attempt to compile and run the following code? class MyParent { int x, y; MyParent(int x, int y) { this.x = x; this.y = y; } public int addMe(int x, int y) { return this.x + x + y + this.y; } public int addMe(MyParent myPar) { return addMe(myPar.x, myPar.y); } } class MyChild extends MyParent { int z; MyChild (int x, int y, int z) { super(x,y); this.z = z; } public int addMe(int x, int y, int z) { return this.x + x + this.y + y + this.z + z; } public int addMe(MyChild myChi) { return addMe(myChi.x, myChi.y, myChi.z); } public int addMe(int x, int y) { return this.x + x + this.y + y; } } public class MySomeOne { public static void main(String args[]) { MyChild myChi = new MyChild(10, 20, 30); MyParent myPar = new MyParent(10, 20); int x = myChi.addMe(10, 20, 30); int y = myChi.addMe(myChi); int z = myPar.addMe(myPar); System.out.println(x + y + z); } }

  1. 300

  2. 240

  3. 120

  4. Compilation error


Correct Option: A

What will be the result of executing the following code? 1. boolean a = true; 2. boolean b = false; 3. boolean c = true; 4. if (a == true) 5. if (b == true) 6. if (c == true) System.out.println("Some things are true in this world"); 7. else System.out.println("Nothing is true in this world!"); 8. else if (a && (b = c)) System.out.println("It's too confusing to tell what is true and what is false"); 9. else System.out.println("Hey this won't compile");

  1. The code won't compile

  2. "Some things are true in this world" will be printed

  3. "Hey this won't compile" will be printed

  4. None of these


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) The code won't compile - This option is incorrect. The code will compile without any syntax errors.

Option B) "Some things are true in this world" will be printed - This option is incorrect. The code will not reach the line that prints this statement because the conditions in the if statements are not met.

Option C) "Hey this won't compile" will be printed - This option is incorrect. The code will compile successfully.

Option D) None of these - This option is correct. The correct answer is none of the above.

The code will execute as follows:

  • Line 1: a is assigned true.
  • Line 2: b is assigned false.
  • Line 3: c is assigned true.
  • Line 4: The condition a == true is true, so the code proceeds to the next line.
  • Line 5: The condition b == true is false, so the code does not proceed to the next line.
  • Line 6: The condition c == true is true, so the code prints "Some things are true in this world".
  • Line 7: The code does not reach this line because the previous if statement was executed.
  • Line 8: The code does not reach this line because the previous if statement was executed.
  • Line 9: The code does not reach this line because the previous if statement was executed.

Therefore, the output will be "Some things are true in this world". None of the given options correctly describe the output, so the correct answer is D) None of these.

What will be the result of executing the following code? // Filename; SuperclassX.java package packageX; public class SuperclassX { protected void superclassMethodX() { } int superclassVarX; } // Filename SubclassY.java 1. package packageX.packageY; 2. 3. public class SubclassY extends SuperclassX 4. { 5. SuperclassX objX = new SubclassY(); 6. SubclassY objY = new SubclassY(); 7. void subclassMethodY() 8. { 9. objY.superclassMethodX(); 10. int i; 11. i = objY.superclassVarX; 12. } 13. }

  1. Compilation error at line 5

  2. Compilation error at line 9

  3. Runtime exception at line 11

  4. None of these


Correct Option: D

What is displayed when the following code is compiled and executed? String s1 = new String("Test"); String s2 = new String("Test"); if (s1==s2) System.out.println("Same"); if (s1.equals(s2)) System.out.println("Equals");

  1. Same

  2. Equals

  3. The code compiles, but nothing is displayed upon execution.

  4. The code fails to compile


Correct Option: B

AI Explanation

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

Option A) Same - This option is incorrect. The code does not print "Same" because the "==" operator compares the references of the two objects, not their actual content.

Option B) Equals - This option is correct. The code prints "Equals" because the ".equals()" method compares the content of the two objects, and since the content of both "s1" and "s2" is "Test", the condition is true and "Equals" is displayed.

Option C) The code compiles, but nothing is displayed upon execution - This option is incorrect. Something is displayed upon execution because the code contains print statements.

Option D) The code fails to compile - This option is incorrect. The code does compile successfully.

The correct answer is B) Equals. This option is correct because the ".equals()" method compares the content of the two strings, and since the content is the same, the condition is true and "Equals" is printed.

What will be output of this program? String str="TCS"; str.concat("Bangalore");

  1. TCS

  2. Bangalore

  3. TCS Bangalore

  4. Syntax Error


Correct Option: A

which class provides member functions for device-context operations, working with drawing tools, type-safe graphics device interface (GDI) object selection, and working with colors and palettes?

  1. CDOCItem

  2. CDC

  3. CBrush

  4. CAnimateCtrl


Correct Option: B

A ____________is a collection that associates a key object with a value object.

  1. Array

  2. List

  3. Map

  4. Vector


Correct Option: C

Useful Features of CObject classes are

  1. serialization support

  2. platform independent

  3. object diagnostic output

  4. run-time class information


Correct Option: A,C,D

The CPropertyPage class is declared in which header file?

  1. afxdlg.h header file.

  2. afxdlgs.h header file

  3. afxprp.h header file

  4. afxproppg.h header file


Correct Option: B

The framework uses ____________ to connect messages and commands to their handler functions.

  1. MapHandler

  2. CommandMaps

  3. HandleCommands

  4. Message maps


Correct Option: D
- Hide questions