EXAM PACK
FOR ASSISTANCE WITH THIS MODULE +27 67 171 1739
, 2023 Assignment 2 MCQ
1) Consider the following program and predict the output
public class Test {
public void print(Integer i) {
System.out.println("Integer");
}
public void print(int i) {
System.out.println("int");
}
public void print(long i) {
System.out.println("long");
}
public static void main(String args[]) {
Test test = new Test();
test.print(10);
}
}
a. Integer
b. The program results in a compiler error (“ambiguous overload”).
c. Long
d. int
2) Which term best describes "a program that duplicates the look and feel of a particular
device"?
a. operating system
b. mobile application
c. emulator
d. smartphone
3) What will be the output of following Java code?
public class Main {
public static void main(String[] args) {
System.out.println(Math.copySign(100.6, -200.6));
}
}
a. -200.6
b. 100.6
c. -100.6
d. 200.6
,4) Consider the following program:
class SuperClass {
SuperClass() {
foo();
}
public void foo() {
System.out.println("In SuperClass.foo()");
}
}
Class SubClass extends SuperClass {
private String member;
public SubClass() {
member = "HI";
}
public void foo() {
System.out.println("In SubClass.foo(): " + member.toLowerCase());
}
}
public class Test {
public static void main(String[] args){
SuperClass reference = new SubClass();
reference.foo();
This program prints the following:
a. In Derived.foo(): hi
b. In SuperClass.foo() In Derived.foo(): hi
c. In SuperClass.foo()
d. This program throws a NullPointerException.
5) Which of the following statements is a way of making more Java functions available to your
specific program?
a. import statement
b. include statement
c. reference statement
d. assignment statement
6) Which of the following is the parent class of service?
a. object
b. contextThemeWrapper
c. Context
d. contextWrapper
, 7) Which term best describes a blueprint or a template for creating objects by defining its
properties?
a. Widget
b. App
c. Class
d. Control
8) What is the return type of a method that returns nothing?
a. int
b. Double
c. void
d. null
9) choose the correct option based on this program:
import java.util.*;
class UtilitiesTest {
public static void main(String[] args) {
List < int > intList = new ArrayList < > ();
intList.add(10);
intList.add(20);
System.out.println("The list is: " + intList);
a. It prints the following: The list is: [10, 20]
b. It results in a runtime exception
c. It prints the following: The list is: [20, 10]
d. It results in a compiler error