0

programming languages Online Quiz - 272

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

void main(){ char far *p = 0x417; *p=64; }

  1. Reboot the Machine

  2. Disable the print screen key

  3. Change the default screen color

  4. puts Capslock on


Correct Option: D

void main() { int a[2][3]={{1,2,3},{4,5,6}}; printf("%d\n",++**(a+1)); }

  1. 5

  2. garbage value

  3. compile error

  4. 2


Correct Option: A

Which of the following operator when used with numbers is not efficient ?

  1. NOT >

  2. NOT

  3. NOT =

  4. None of the above


Correct Option: C

ejbCreate() method of CMP bean returns

  1. null

  2. Primary Key class

  3. Home Object

  4. Remote Object


Correct Option: A

Which of the following statements hold true in the following program? package generics; import java.util.ArrayList; import java.util.List; public class Ques04 { public static void main(String[] args) { List extends Instrument> allInstruments = new ArrayList(); // -->X allInstruments.add(new Guitar()); allInstruments.add(new Violin()); } } interface Instrument { public void play(); } class Guitar implements Instrument { public void play(){ System.out.println("Playing Guitar."); } } class Violin implements Instrument { public void play(){ System.out.println("Playing Violin."); } }

  1. The program will not compile.

  2. The program will compile but will throw run-time exception.

  3. The statement 'X' manifests that objects of type Instrument as well as sub-types can be added to the list 'allInstruments'.

  4. It is not possible to add any type of objects to the list 'allInstruments'.


Correct Option: A

what is the output of compiling an running the following code? import java.util.*; class CheckTest { public static void main(String [] args) { Hashtable ht = new Hashtable(); ht.put("chec", "check"); ht.put(1000, "check"); // line 1 ht.put("check", 20.01); // line 2 System.out.print(ht.get("chec") + " "); System.out.print(ht.get(1000) + " "); //line 3 System.out.print(ht.get("check")); //line 4 } }

  1. Compilation fails due to error at line 1,2,3,4

  2. Compilation fails due to error at line 3,4

  3. Compiles fine and exception is thrown at runtime.

  4. Compiles fine and prints "check check 20.01"


Correct Option: D
Explanation:

To solve this question, the user needs to understand the concepts of Hashtable and data types in Java.

The code creates a Hashtable named ht, which maps keys to values. It puts three key-value pairs into the Hashtable:

  • "chec" is mapped to "check"
  • 1000 is mapped to "check"
  • "check" is mapped to 20.01

The code then retrieves the values corresponding to three keys and prints them out.

Now let's go through each option and explain why it is right or wrong:

Option A: Compilation fails due to error at line 1,2,3,4 This option is incorrect. There are no compilation errors in this code.

Option B: Compilation fails due to error at line 3,4 This option is incorrect. There are no compilation errors in this code.

Option C: Compiles fine and exception is thrown at runtime. This option is incorrect. The code compiles without errors, but no exception is thrown at runtime. The output of the code is "check check 20.01".

Option D: Compiles fine and prints "check check 20.01" This option is correct. The code compiles without errors, and when run, it prints "check check 20.01". The keys "chec" and 1000 are mapped to the value "check", while the key "check" is mapped to the value 20.01.

Therefore, the answer is: D. Compiles fine and prints "check check 20.01".

A JSP page is opened in a particular Session. A button is present in that JSP page onclick of which a new Window gets opened.

  1. The Session is not valid in the new Window

  2. The Session is valid in the new Window

  3. The Scope is not valid in the new Window

  4. The Scope is valid in the new Window


Correct Option: B

AI Explanation

To answer this question, we need to understand how sessions and scopes work in web applications.

When a user opens a JSP page, a session is created for that user. The session allows the server to store and retrieve information specific to that user throughout their browsing session.

In this scenario, when the user clicks on the button and a new window opens, the session is still valid in the new window. This means that the server can still access and retrieve the session data for that user.

On the other hand, scopes in JSP refer to the lifespan and visibility of variables within a JSP page. The most commonly used scopes are request, session, and application. These scopes determine how long a variable will exist and be accessible within a JSP page.

However, the scope of variables does not directly affect the validity of the session in the new window. The session remains valid regardless of the scope of variables used in the JSP page.

Therefore, the correct answer is B) The Session is valid in the new Window.

In the init(ServletConfig) method of Servlet life cycle, what method can be used to access the ServletConfig object ?

  1. getServletInfo()

  2. getInitParameters()

  3. getServletConfig()

  4. None of the above


Correct Option: C

What is the output for the following lines of code? import java.io.*; public class FileHandling { public static void main (String[] arg) throws Exception { File f = new File ("ll.txt"); FileOutputStream s = new FileOutputStream(f); PrintStream p = new PrintStream (s); p.println("hi"); } }

  1. A. It would fail to compile

  2. B. It would generate a run-time error on execution.

  3. C. It would execute, but ask the user to specify the directory in which to create ll.txt.

  4. D. It would execute without an error and print "hi" to a file called ll.txt


Correct Option: D
  1. A) Strings are immutable, compilation error at line 3.

  2. B) Strings are immutable, runtime exception at line 3.

  3. C) Prints "Welcome".

  4. D) Prints "Welcome to Java!".


Correct Option: C

What is the output for the following lines of code? 1: class Test 2: { 3: static void show() 4: { 5: System.out.println("Static method in Test"); 6: } 7: } 8: public class Q4 extends Test 9: { 10: void show() 11: { 12: System.out.println("Overridden static method in Q4"); 13: } 14: public static void main(String[] args) 15: { 16: } 17: }

  1. Compilation error at line 3.

  2. Compilation error at line 10.

  3. No compilation error, but runtime exception at line 3.

  4. No compilation error, but runtime exception at line 10.


Correct Option: B

AI Explanation

To answer this question, we need to understand the concept of method overriding in Java.

In the given code, we have a class Test with a static method show() defined at line 3. The show() method simply prints "Static method in Test" to the console.

Then, we have another class Q4 which extends the Test class. In the Q4 class, we have a method show() defined at line 10. This method is an instance method and it also prints a message to the console: "Overridden static method in Q4".

Now, let's go through each option to understand why it is correct or incorrect:

Option A) Compilation error at line 3 - This option is incorrect. There is no compilation error at line 3. The show() method in the Test class is a static method, and it can be called using the class name.

Option B) Compilation error at line 10 - This option is correct. The show() method in the Q4 class is an instance method and it is trying to override the static method show() in the Test class. However, it is not possible to override a static method with an instance method. Therefore, a compilation error will occur at line 10.

Option C) No compilation error, but runtime exception at line 3 - This option is incorrect. There is no runtime exception at line 3. The show() method in the Test class is a valid static method.

Option D) No compilation error, but runtime exception at line 10 - This option is incorrect. There is no runtime exception at line 10. The compilation error at line 10 prevents the code from executing, so there won't be any runtime exception.

The correct answer is B. There is a compilation error at line 10 because it is not possible to override a static method with an instance method in Java.

What is the output for the following lines of code? 1: public class Q8 2: { 3: int i = 20; 4: static 5: { 6: int i = 10; 7: 8: } 9: public static void main(String[] args) 10: { 11: Q8 a = new Q8(); 12: System.out.println(a.i); 13: } 14: }

  1. Compilation error, variable "i" declared twice.

  2. Compilation error, static initializers for initialization purpose only.

  3. Prints 10.

  4. Prints 20.


Correct Option: D
  1. MyOuter.MyInner m = new MyOuter.MyInner();

  2. MyOuter.MyInner mi = new MyInner();

  3. MyOuter m = new MyOuter();

  4. MyInner mi = new MyOuter.MyInner();


Correct Option: A

Properties meant for protecting a field in a class?

  1. True

  2. False


Correct Option: A

You can not change fields internal implementation over time?

  1. True

  2. False


Correct Option: B

We achieve Encapsulating Type State with Properties?

  1. True

  2. False


Correct Option: A
- Hide questions