Java and C++ Programming Quiz
Test your knowledge of Java APIs, programming concepts, and C++ language features including object-oriented programming principles.
Questions
We can assign NULL to const pointer after initializing once.
- True
- False
What makes C++ to support function overloading ?
- Polymorphism
- Inheritance
- Name Mangling
- Function Signature
Following functionality in C++ violates the encapsulation.
- Pointers
- Friend Function
- Access Specifiers
- None
What is the memory of a class that contains niether data members nor member functions ?
- 0 bytes
- 1 bit
- same as sizeof(int)
- 1 byte
How many differnces are there between structures in C and C++ ?
- 1
- No difference
- 2
- 5
How many differnces we can find between structures in C and C++ ?
- 1
- No difference
- 2
- 5
We can initialize following type of variables in class declaration.
- static
- const
- extern
- none
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());
}
}
- 57 22
- 45 38
- 45 57
- An exception occurs at runtime.
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 */
- Compilation fails.
- An error occurs at runtime.
- It prints "foobarhi"
- It prints "barhi"
In which all cases does an exception gets generated. Select the two correct answers. int i = 0, j = 1;
- if((i == 0) || (j/i == 1))
- if((i == 0) | (j/i == 1))
- if((i != 0) && (j/i == 1))
- if((i != 0) & (j/i == 1))
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);
}
}
- result = 1
- result = 10
- result = 11
- result = 11010
JAIN stands for Java Integrated Networks
- True
- False
JAF stands for Java Activation Framework
- True
- False
JCA stands for Java Communications API
- True
- False
JCE stands for Java Communication Extension
- True
- False
JDO stands for Java Data Objects
- True
- False
JSSE stands for Java Socket Service Extension
- True
- False
JAX-WS stands for Java API for XML Web Services
- True
- False
JAX-RS stands for Java API for RESTful Web Services
- True
- False