Java and C++ Programming Quiz

Test your knowledge of Java APIs, programming concepts, and C++ language features including object-oriented programming principles.

19 Questions Published

Questions

Question 1 True/False

We can assign NULL to const pointer after initializing once.

  1. True
  2. False
Question 2 Multiple Choice (Single Answer)

What makes C++ to support function overloading ?

  1. Polymorphism
  2. Inheritance
  3. Name Mangling
  4. Function Signature
Question 3 Multiple Choice (Single Answer)

Following functionality in C++ violates the encapsulation.

  1. Pointers
  2. Friend Function
  3. Access Specifiers
  4. None
Question 4 Multiple Choice (Single Answer)

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
Question 5 Multiple Choice (Single Answer)

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

  1. 1
  2. No difference
  3. 2
  4. 5
Question 6 Multiple Choice (Single Answer)

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

  1. 1
  2. No difference
  3. 2
  4. 5
Question 7 Multiple Choice (Single Answer)

We can initialize following type of variables in class declaration.

  1. static
  2. const
  3. extern
  4. none
Question 8 Multiple Choice (Single Answer)

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.
Question 9 Multiple Choice (Single Answer)

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"
Question 10 Multiple Choice (Multiple Answers)

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))
Question 11 Multiple Choice (Single Answer)

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
Question 12 True/False

JAIN stands for Java Integrated Networks

  1. True
  2. False
Question 13 True/False

JAF stands for Java Activation Framework

  1. True
  2. False
Question 14 True/False

JCA stands for Java Communications API

  1. True
  2. False
Question 15 True/False

JCE stands for Java Communication Extension

  1. True
  2. False
Question 16 True/False

JDO stands for Java Data Objects

  1. True
  2. False
Question 17 True/False

JSSE stands for Java Socket Service Extension

  1. True
  2. False
Question 18 True/False

JAX-WS stands for Java API for XML Web Services

  1. True
  2. False
Question 19 True/False

JAX-RS stands for Java API for RESTful Web Services

  1. True
  2. False