0

programming languages Online Quiz - 11

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

Libname statements can be used to create excel workbooks

  1. True

  2. False


Correct Option: A

We can assign NULL to const pointer after initializing once.

  1. True

  2. False


Correct Option: B

What makes C++ to support function overloading ?

  1. Polymorphism

  2. Inheritance

  3. Name Mangling

  4. Function Signature


Correct Option: C

Following functionality in C++ violates the encapsulation.

  1. Pointers

  2. Friend Function

  3. Access Specifiers

  4. None


Correct Option: B

What is the memory of a class that contains niether data members nor member functions ?

  1. 0 bytes

  2. 1 bit

  3. same as sizeof(int)

  4. 1 byte


Correct Option: D

How many differnces are there between structures in C and C++ ?

  1. 1

  2. No difference

  3. 2

  4. 5


Correct Option: D

How many differnces we can find between structures in C and C++ ?

  1. 1

  2. No difference

  3. 2

  4. 5


Correct Option: A

We can initialize following type of variables in class declaration.

  1. static

  2. const

  3. extern

  4. none


Correct Option: D

What will be the output of the program?

public abstract class AbstractTest {
 public int getNum() {
  return 45;
 }
 public abstract class Bar {
  public int getNum() {
   return 38;
  }
 }
 public static void main(String[] args) {
  AbstractTest t = new AbstractTest() {
   public int getNum() {
    return 22;
   }
  };
  AbstractTest.Bar f = t.new Bar() {
   public int getNum() {
    return 57;
   }
  };
  System.out.println(f.getNum() + " " + t.getNum());
 }
}
  1. 57 22

  2. 45 38

  3. 45 57

  4. An exception occurs at runtime.


Correct Option: A

What will be the output of the program?

public class Foo {
 Foo() {
  System.out.print("foo");
 }
 class Bar {
  Bar() {
   System.out.print("bat");
  }
  public void go() {
   System.out.print("hi");
  }
 } /* class Bar ends */
 public static void main(String[] args) {
  Foo f = new Foo();
  f.makeBar();
 }
 void makeBar() {
  (new Bar() {}).go();
 }
} /* class Foo ends */
  1. Compilation fails.

  2. An error occurs at runtime.

  3. It prints "foobarhi"

  4. It prints "barhi"


Correct Option: C

AI Explanation

To determine the output of the program, let's go through the code step by step:

  1. The program defines a class named Foo.
  2. Inside Foo, a constructor Foo() is defined, which prints "foo" when an object of Foo is created.
  3. Inside Foo, another class named Bar is defined.
  4. Inside Bar, a constructor Bar() is defined, which prints "bat" when an object of Bar is created.
  5. Inside Bar, a method go() is defined, which prints "hi".
  6. The main method is defined inside Foo and is the starting point of the program.
  7. In the main method, an object f of Foo is created, which prints "foo" when created.
  8. Next, the makeBar() method is called on f.
  9. Inside the makeBar() method, a new anonymous object of Bar is created using the syntax (new Bar() {}). This object is created and its constructor is called, printing "bat".
  10. Then, the go() method is called on this new object, printing "hi".

Therefore, the output of the program will be "foobarhi", which corresponds to option C.

In which all cases does an exception gets generated. Select the two correct answers. int i = 0, j = 1;

  1. if((i == 0) || (j/i == 1))

  2. if((i == 0) | (j/i == 1))

  3. if((i != 0) && (j/i == 1))

  4. if((i != 0) & (j/i == 1))


Correct Option: B,D

AI Explanation

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

Option A) if((i == 0) || (j/i == 1)) - This option is incorrect because it uses the logical OR operator (||) which short-circuits and does not evaluate the second part of the condition if the first part is true. Therefore, an exception will not be generated in this case.

Option B) if((i == 0) | (j/i == 1)) - This option is correct because it uses the bitwise OR operator (|) which evaluates both parts of the condition. If i is 0, the second part of the condition (j/i == 1) will be evaluated, and since dividing by 0 is undefined, an exception will be generated.

Option C) if((i != 0) && (j/i == 1)) - This option is incorrect because it uses the logical AND operator (&&) which short-circuits and does not evaluate the second part of the condition if the first part is false. Therefore, an exception will not be generated in this case.

Option D) if((i != 0) & (j/i == 1)) - This option is correct because it uses the bitwise AND operator (&) which evaluates both parts of the condition. If i is not 0, the second part of the condition (j/i == 1) will be evaluated, and since dividing by 0 is undefined, an exception will be generated.

The correct answers are B) if((i == 0) | (j/i == 1)) and D) if((i != 0) & (j/i == 1)). These options are correct because they use the bitwise OR and bitwise AND operators, respectively, which evaluate both parts of the condition and can result in an exception if dividing by 0.

What will be the output of the program?

public class WrapTest {
 public static void main(String[] args) {
  int result = 0;
  short s = 42;
  Long x = new Long("42");
  Long y = new Long(42);
  Short z = new Short("42");
  Short x2 = new Short(s);
  Integer y2 = new Integer("42");
  Integer z2 = new Integer(42);
  if (x == y) /* Line 13 */ result = 1;
  if (x.equals(y)) /* Line 15 */ result = result + 10;
  if (x.equals(z)) /* Line 17 */ result = result + 100;
  if (x.equals(x2)) /* Line 19 */ result = result + 1000;
  if (x.equals(z2)) /* Line 21 */ result = result + 10000;
  System.out.println("result = " + result);
 }
}
  1. result = 1

  2. result = 10

  3. result = 11

  4. result = 11010


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) result = 1 - This option is incorrect because it only considers the first if statement, which checks if x and y are equal using the == operator. However, the == operator is used to compare references for objects, not their values.

Option B) result = 10 - This option is correct because it considers the second if statement, which checks if x and y are equal using the equals() method. Since x and y have the same value, this condition is true, and result is incremented by 10.

Option C) result = 11 - This option is incorrect because it assumes that the condition in the first if statement is true. However, as mentioned earlier, the == operator is used to compare references, not values.

Option D) result = 11010 - This option is incorrect because it assumes that all the if statements are true. However, only the second if statement is true, so result is incremented by 10.

The correct answer is B) result = 10. This option is correct because the second if statement, which checks if x and y are equal using the equals() method, is true and increments result by 10.

JAIN stands for Java Integrated Networks

  1. True

  2. False


Correct Option: A

AI Explanation

To answer this question, we need to understand what JAIN stands for.

JAIN stands for Java INtegrated Networks, not Java Integrated Networks.

So the correct answer is:

A) True - This option is correct because JAIN stands for Java INtegrated Networks.

JAF stands for Java Activation Framework

  1. True

  2. False


Correct Option: B

JCA stands for Java Communications API

  1. True

  2. False


Correct Option: A

JCE stands for Java Communication Extension

  1. True

  2. False


Correct Option: B

JDO stands for Java Data Objects

  1. True

  2. False


Correct Option: A

JSSE stands for Java Socket Service Extension

  1. True

  2. False


Correct Option: B

JAX-WS stands for Java API for XML Web Services

  1. True

  2. False


Correct Option: A

JAX-RS stands for Java API for RESTful Web Services

  1. True

  2. False


Correct Option: A
- Hide questions