0

programming languages Online Quiz - 192

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

What happens when you compare two primitives of different numerical types?

  1. compiler error

  2. smaller type is promoted

  3. must explicitly cast

  4. none of the above


Correct Option: B

Are you allowed to have more than one top-level(non-inner) class definition per source file?

  1. True

  2. False


Correct Option: A

Assume the bit pattern of byte x is: 10110001. What will the sign of x be after x>>2?

  1. postive

  2. negative

  3. can't be find

  4. none of the above


Correct Option: B

A class can define two methods with the same name as long as the return types are different

  1. True

  2. False


Correct Option: B

All exceptions inherit from

  1. java.lang.Exception

  2. java.lang.Error

  3. java.lang.Throwable

  4. none of the above


Correct Option: C

What happens when you compare two primitives of different numerical types?

  1. compiler error

  2. smaller type is promoted

  3. must explicitly cast

  4. none of the above


Correct Option: B

public static void main(String [] args) { int x = 5; boolean b1 = true; boolean b2 = false; if ((x == 4) && !b2 ) System.out.print("1 "); System.out.print("2 "); if ((b2 = true) && b1 ) System.out.print("3 "); } } What is the result?

  1. 1,3

  2. 2,3

  3. Compilation Error

  4. Exception


Correct Option: B
Explanation:

To solve this question, the user needs to know the basics of boolean expressions and how they work in Java programming. They also need to understand the concept of conditional statements.

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

The code starts by initializing the variable x to 5, and the boolean variables b1 and b2 to true and false, respectively.

The first conditional statement checks if the value of x is equal to 4 and if b2 is false. Since neither condition is true, the code skips the first print statement and moves on to the second one.

The second print statement prints "2" to the console.

The second conditional statement assigns the value true to b2 and then checks if b1 is also true. Since both conditions are true, the code executes the third print statement, printing "3" to the console.

Therefore, the output of the program is:

2 3

So, the correct answer is:

The Answer is: B

interface I{ void f1(); // 1 public void f2(); // 2 protected void f3(); // 3 private void f4(); // 4 } which lines generate compile time errors?

  1. compiletime error at lines 1,2,3,4

  2. compiletime error at line 3

  3. compiletime error at line 1

  4. compiletime error at lines 3,4


Correct Option: D

AI Explanation

To answer this question, let's go through each line to understand if it generates a compile-time error:

1) void f1(); - This line does not generate a compile-time error because the default access modifier for interface methods is public.

2) public void f2(); - This line does not generate a compile-time error because the access modifier public is allowed for interface methods.

3) protected void f3(); - This line generates a compile-time error because the access modifier protected is not allowed for interface methods. Interface methods can only have public access modifier.

4) private void f4(); - This line generates a compile-time error because the access modifier private is not allowed for interface methods. Interface methods can only have public access modifier.

Therefore, the correct answer is option D) compile time error at lines 3,4.

class C1{ public void m1(){ // 1 } } class C2 extends C1{ //2 private void m1(){ } }

  1. compile time error at line1

  2. compile time error at line2

  3. Run time exception

  4. None Of the above


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) compile time error at line 1 - This option is incorrect because there is no compile time error at line 1. The method m1() in class C1 is declared correctly.

Option B) compile time error at line 2 - This option is correct because there is a compile time error at line 2. In class C2, the method m1() is attempting to override the method m1() in the parent class C1. However, the method m1() in the parent class C1 is not accessible from the subclass C2 because it is declared as private. Therefore, the subclass cannot override it, resulting in a compile time error.

Option C) Run time exception - This option is incorrect because the code does not contain any runtime exceptions. The error occurs during compilation, not during runtime.

Option D) None of the above - This option is incorrect because the correct answer is option B, as explained above.

The correct answer is B) compile time error at line 2. This option is correct because the method m1() in class C2 cannot override the private method m1() in class C1.

class A extends Thread { public void run() { System.out.print("A"); } } class B { public static void main (String[] args) { A a = new A(); a.start(); a.start(); // 1 } }

  1. Run Time Exception

  2. Compile Error

  3. the code compile and runs fail

  4. None of the above


Correct Option: A

What type of inheritance does Java have?

  1. Single Inheritence

  2. Double Inheritence

  3. Multiple Inheritence

  4. Class Inheritence


Correct Option: A

Java runs on.

  1. Windows

  2. Unix

  3. Solaris

  4. All of the above


Correct Option: D

The Java interpreter is used for the execution of the source code.

  1. True

  2. False


Correct Option: A

A Vector is declared as follows. What happens if the code tried to add 6 th element to this Vector new vector(5,10)

  1. The element will be successfully added

  2. ArrayIndexOutOfBounds Exception

  3. The Vector allocates space to accommodate up to 15 elements

  4. None of the above


Correct Option: A,C

Which is the data structure used to store sorted map elements

  1. HashSet

  2. Hashmap

  3. Map

  4. TreeMap


Correct Option: D

Which of the following is true ?

  1. Stateless session beans doesn’t preserve any state across method calls

  2. Stateful session beans can be accesses by multiple users at the same time

  3. None of the above

  4. Allof the above


Correct Option: A

Stateful Session beans contain

  1. Home Interface

  2. Remote Interface

  3. Bean Class

  4. All of the above


Correct Option: D

A method is defined in a class as : void processUser(int i) { } If this method is overriden in a sub class,

  1. the new method should return int

  2. the new method can return any type of values

  3. the argument list of new method should exactly match that of overriden method

  4. the return type of new method should exactly match that of overriden method


Correct Option: C,D

What is the output of following piece of code ? int x = 2; switch (x) { case 1:System.out.println(”1?); case 2: case 3:System.out.println(”3?); case 4: case 5:System.out.println(”5?);

  1. No output

  2. 3 and 5

  3. 1, 3 and 5

  4. 3


Correct Option: B

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
- Hide questions