Quiz
AISE 2205
Create a free account to finish this quiz
Save your progress and see your final score.
Already have an account? Sign in
Questions in this quiz (80)
1A recursive call is always expensive in terms of memory usage
- ATrue
- BFalse
2A recursive call will always take more time to execute compared to an iterative call for the same problem
- ATrue
- BFalse
3If x is a reference-variable of a class called MyClass, and it is instantiated in the driver method, the following two statements in the driver method will execute the same result:
System.out.println(x);
System.out.println(x.toString());- ATrue
- BFalse
4What are some reasons one would use an enhanced for-each loop instead of a for loop?
1. If one wishes to access every element of an array
2. If one wishes to modify elements of the array
3. If one wishes to refer to elements through a variable name instead- A1 and 3 only
- B2 and 3 only
- COnly 1
- DAll the options are correct
5What is the output of the following code segment?
int[] numbers = {44, 33, 22, 11};
for (int num : numbers) {
num *= 2;
}
for (int num : numbers) {
System.out.print(num + " ");
}- A88 66 44 22
- B46 35 24 13
- CNone of the choices are correct
- D44 33 22 11
6Given that 'array' is an array-reference of integers and 'target' is an integer value, which of the following best describes the conditions under which the following code segment will return true?
boolean temp = false;
for (int val : array) {
temp = (target == val);
}
return temp;- AWhenever the first element in array is equal to target
- BWhenever array contains any element which equals target
- Cwhenever only 1 element in array is equal to target
- DWhenever the last element in array is equal to target
7Which one of the following names follows the naming convention for a class name in Java?
- AmyFirstClass
- BMyFirstClass
- CMY_FIRST_CLASS
- Dmyfirstclass
8In the following Java statement, what does 'out' represent?
System.out.println("Welcome to Java!");- AA method
- BA PrintStream type reference-variable, which is a field in the System class
- CA class
- DA package
9How many class names do you see in the following code?
public class MyClass {
public static void main(String[] args) {
System.out.println("The answer is: Yes");
}
}- A1
- B2
- C3
- DNone of the choices are correct
10In Java, main() is a method name
- ATrue
- BFalse
11What will appear as the output after executing the following Java statement:
System.out.println(3*(1/2*4)-5);- A-5
- B1
- C10
- D-9
12What will be printed on the console after the following statements are executed in Java?
int a = 5, b = 14;
System.out.println(a%b + b%a);- A4
- B5
- C8
- D9
13Which of the following results for variables a and b is correct after the second statement in a Java code?
int a = 4, b = 8;
a = a + b++;- Aa is 4
b is 9 - Ba is 13
b is 9 - Ca is 5
b is 8 - Da is 12
b is 9
- Aa is 4
14In the Java statement: System.out.println(-b + c - d); the negative sign before the variable b is a _____ operator. Choose the best answer.
- Aunary
- Bbinary
- Cternary
- DNone of the choices are correct
15Which one of these is NOT a primitive data type in Java?
- Afloat
- BString
- Cboolean
- Dlong
16In Java, which one of these data types is ideal to store the number 137.99?
- Aint
- Bdouble
- Clong
- Dboolean
17Any problem that can be solved recursively can also be solved iteratively
- ATrue
- BFalse
18Without a base case, a recursive method will call itself only once and stop
- ATrue
- BFalse
19A problem can be solved recursively if it can be broken down into successive smaller problems that are identical to the overall problem
- ATrue
- BFalse
20A recursion is never absolutely required to solve a problem
- ATrue
- BFalse
21A wrapper class is a class that is 'wrapped around' a primitive data type and allows to create reference-variables (Object-instance) instead of variables
- ATrue
- BFalse
22In a recursive method, the number of times a method calls itself is known as...
- Athe cyclic identity
- Bthe method heap
- Cthe depth of recursion
- Dthe call count
23The signature of a method consists of...
- Athe parameter list
- Bthe method name and the parameter list
- Cthe method name
- Dthe return type, method name, and the parameter list
24Based on the following assignments, what will be the data-types of x, y, and z?
x = '1';
y = 1.0;
z = "1.0"- Ax is a char-type variable, y is a double-type variable and z is a String type reference-variable.
- BAll the variables are of integer-type.
- Cx is a char-type variable, y is an int-type variable and z is a String type reference-variable.
- Dx is a char-type variable, y is a float-type variable and z is a String type reference-variable.
25Which of the following statements converts an int variable named number to a string and stores the value in the String type reference variable named str?
- AString str = number.Integer.toString(str);
- BString str = integer.toString(number);
- CString str = Integer.toString(number);
- DString str = integer(number);
26The method header is left blank (the long dash) in the following code. Fill in the header.
public class GenericMethodDemo {
public static void main(String[] args ) {
Integer[] integers = {1, 2, 3, 4, 5};
String[] strings = {"London", "Paris", "New York", "Austin"};
print(integers);
print(strings);
}
__________________________________________ {
for (int i = 0; i < list.length; i++)
System.out.print(list[i] + " ");
System.out.println();
}
}- Apublic static <T> void main(T list)
- Bpublic static <T> void main(T[] list)
- Cpublic static void <T> main(T[] list)
- Dpublic static void main(T[] list)
27Which of the following is a checked exception in Java?
- AIOException
- BIllegalArgumentException
- CArithmeticException
- DNullPointerException
28What will be the output of the following code, if the user enters 3 and 0 respectively, when prompted?
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Enter two integers: ");
int number1 = input.nextInt();
int number2 = input.nextInt();
try {
System.out.println(number1 + " / " + number2 + " is "+ (number1 / number2));
} catch (Exception ex) {
System.out.print("Exception: divide by zero!");
}
System.out.println(" Good bye!");
}- AGood bye!
- BException: divide by zero! Good bye!
- CSince no exception is thrown from the try-block, the code will not compile
- DException: divide by zero!
29Exception handling is always expensive in terms of memory
- ATrue
- BFalse
30The following code will compile.
public class Fruit {
public String aName;
public Fruit(String name) {
System.out.println("Fruit's constructor is invoked");
}
}
public class Apple extends Fruit {
public Apple(String name) {
super(name);
System.out.println("Apple's constructor is invoked");
}
}
public class DriverClass {
public static void main(String[] args) {
Apple x = new Apple("Gala");
}
}- ATrue
- BFalse
31Which of the following statements is true concerning abstract classes in Java?
- AAn abstract class can be used to instantiate an object of its own by using the new operator
- BAn abstract class can be used to create an object reference (reference variable)
- CAll abstract methods declared in an abstract class must be defined inside the same abstract class
- DConstructors can be abstract
32What type of polymorphism is observed in the following code:
class Cat {
public void sound() {System.out.println("Cats's meow");}
}
class Kitten extends Cat {
public void sound() {System.out.println("Kitten's meow");}
}
public class MyClass {
public static void main(String[] args) {
Kitten pumpkin = new Kitten();
pumpkin.sound();
}
}- AMethod overriding
- BConstructor overloading
- CMethod overloading
- DNone of the choices are correct
33What type of polymorphism is observed in the following code:
class Cat {
public cat(){System.out.println("Cats's constructor");}
}
class Kitten extends Cat {
public void sound()
{System.out.println("Cats's meow");}
public void sound(String kitten)
{System.out.println(kitten + "'s meow");}
}
public class MyClass {
public static void main(String[] args) {
Kitten pumpkin = new Kitten();
pumpkin.sound();
}
}- AMethod overloading
- BMethod overriding
- CConstructor overloading
- DNone of the choices are correct
34What type of polymorphism is observed in the following code:
class Cat {
public cat(){System.out.println("Cats's constructor");}
}
class Kitten extends Cat {
public Kitten()
{System.out.println("Kitten's constructor");}
public Kitten(String k)
{System.out.println(k + "'s constructor");}
public void sound()
{System.out.println("Kitten's meow");}
}
public class MyClass {
public static void main(String[] args) {
Kitten pumpkin = new Kitten();
pumpkin.sound();
}
}- ANone of the choices are correct
- BMethod overloading
- CConstructor overloading
- DMethod overriding
35If you define an abstract class called MyClass (with 2 data-fields) in Java that is inherited by a class called AnotherClass, how many AnotherClass objects are instantiated in the heap once the following statement is executed.
MyClass [] mc = new AnotherClass [10]- A10
- B20
- C0
- D1
- E2
36In the following class header, which class is the superclass?
public class ClassA extends ClassB implements ClassC- AClassB
- BClassA
- CBoth ClassB and ClassC
- DClassC
37To declare a class named A with a generic type, use...
- Apublic class A <E> {...}
- Bpublic class A(E, F) {...}
- Cpublic class A(E) {...}
- Dpublic class A<E, F> {...}
38To create a list to store integers, use...
- AArrayList<int> list = new ArrayList<int>();
- BArrayList<Integer> list = new ArrayList<>();
- CArrayList<Number> list = new ArrayList<>();
- DArrayList<Object> list = new ArrayList<>();
39The method header is left blank (the long dash) in the following code. Fill in the header.
public class GenericMethodDemo {
public static void main(String[] args ) {
Integer[] integers = {1, 2, 3, 4, 5};
String[] strings = {"London", "Paris", "New York", "Austin"};
print(integers);
print(strings);
}
__________________________________________ {
for (int i = 0; i < list.length; i++)
System.out.print(list[i] + " ");
System.out.println();
}
}- Apublic static void print(Integer[] list)
- Bpublic static void print(String[] list)
- Cpublic static void print(Object[] list)
- Dpublic static void print(int[] list)
40To create a generic type bounded by a class called Number, use...
- A<E extends Number>
- B<E extends Integer>
- C<E extends Object>
- D<E>
41If the operand a in a division operation in Java is a float type data, the output of a/b with int b = 0; will result in an ArithmeticException call
- ATrue
- BFalse
42In the following inheritance-chain diagram, what's the relationship between Class_2 (concrete class) and Interface_1?

- AClass_2 and Interface_1 have the same root, which is Object Class
- BThere is no relationship between these two
- CClass_2 implements the methods declared in both Interface_1 and Interface_2
- DClass_2 implements the methods declared in Interface_2 only
43If a double type variable gets 8 bytes of space in the memory, given the array declaration below, how many bytes are stored in the heap?
double[] C = new double[5];- A40
- B45
- C0
- D5
44Given the array declaration below, what is the size of the array in the stack? Note that a double-type variable gets 8 bytes of space in the memory.
double[] C = new double[5];- A5
- B40
- C45
- DNo array is created in the stack!
45Which of the following is a non-linear data structure?
- ANone of the choices are correct
- BStack
- CQueue
- DDoubly linked list
- ESingly linked list
46The throw clause causes an exception to be thrown
- ATrue
- BFalse
47If a class called MyClass derives an Abstract class called AnotherClass, the following statement in the driver method will NOT result in a compilation error. We can assume that both the classes contain no-argument constructors.
AnotherClass[] x = new AnotherClass[5];- ATrue
- BFalse
48A Circle class has one data field of type double called radius. If a double type variable gets 8 bytes of space in the memory, given the array declaration below, how many bytes for radius type data are stored in the heap?
Circle[] C = new Circle[5];- A5
- B8
- C40
- DNone of the choices are correct
- E48
49Which of the data types below could be used to store elements in their natural order based on the compareTo() method
- ACollection
- BSet
- CHashSet
- DLinkedHashSet
- ETreeSet
50What will be the correct choice in filling in the blank for the following Java statement:
Comparable _____ c = new Date();- A<String>
- B<E>
- C<Date>
- D<?>
51Which of the following data structure can most effectively be used to implement backward and forward navigation options of the visited web pages?
- AQueue
- BDoubly Linked List
- CStack
- DSingly Linked List
52Based on the declaration, which of the following Java statements is correct?
List<String> list = new ArrayList<String>();- Alist.add("red");
- Blist.add(new java.util.Date());
- Clist.add(new Integer(100));
- Dlist.add(new ArrayList());
53Which of the following statements in Java can be used to find the maximum object-value in an array of strings called names.
- ACollections.max(Arrays.asList(names));
- BArrays.max(names);
- CArrays.sort(names);
- DCollections.max(names);
- ENone of the choices are correct
54What will be the output of the following code segment?
public class MyArray {
public static void main(String args[]) {
int []arr = {1,2,3,4,5};
System.out.println(arr[5]);
}
}- AThe code will not compile
- B-6
- C-1
- D5
- EThe code will throw ArrayIndexOutOfBoundsException
55Given the inheritance diagram below, which of the following statements in Java is invalid?

- ANone of the choices are valid
- BList<Boolean> list = new ArrayList<Boolean>();
- CAbstractSequentialList<Double> sl = new LinkedList();
- DLinkedHashSet<String> LHS = new HashSet<>();
- EVector<String> VC = new Stack<>();
56A computer program is the implementation of an algorithm
- ATrue
- BFalse
57An algorithm refers to...
- AThe collection of instructions that the computer can understand
- BA code that allows us to type in text materials
- CA set of math equations to derive the solutions of a problem
- DA step-by-step solution to solve a specific problem
58The extension of a java source code file is...
- A.java
- B.obj
- C.class
- D.exe
- E.cpp
59The source code in Java is compiled into a bytecode
- ATrue
- BFalse
60Bytecode is machine dependent
- ATrue
- BFalse
61In the following Java statement, what does System represent?
System.out.println("Welcome to Java!);- AA package
- BA class
- CAn object
- DA method
- ENone of the options are correct
62In Java programming language, the main() method must be declared as a static method of a class
- ATrue
- BFalse
63Which of the following statements is FALSE?
- AIn Java, every class belongs to a class
- BIn Java, the entry point for the java interpreter is the main() method
- CIn Java, a class definition should always be terminated with a semicolon
- Dprintln() is a PrintStream type method
64What will be the value of 'c' after the third statement?
int a = 3, b = 2;
double c;
c = (a+b)/2;- A2.5
- B2.0
- C3.0
- D0
65What will be the value of ‘c’ after the third statement?
float a = 3, b = 2;
int c;
c = (a+b)/2;- A2.5
- B2
- C0
- DThe code will not compile
66What will be the output of the code?
int a = 2, b = 4;
a = ++b;
System.out.println(a + "," + b);- A2, 5
- B4, 4
- C5, 5
- D4, 5
67Output?
int a = 2;
float b = 4.0;
System.out.println(a/b);- A0
- B0.5
- CThe code will result in a Compilation error
- DThe code will result in a Runtime error
68What is the advantage of a recursive approach than an iterative approach?
- AConsumes less memory
- BEasy to implement if the base case is known, and less code in general
- CConsumes more memory
- DMore code must be written
69To create a list to store integers, which of the following statements can be used?
- AArrayList<Integer> list = new ArrayList<Integer>();
- BArrayList<Number> list - new ArrayList<Integer>();
- CArrayList<Object> list = new ArrayList<Integer>();
- DArrayList<int> list = new ArrayList<int>();
70To declare an interface named A with two generic types, which of the following statements can be used?
- Apublic interface A(E, F) { … }
- Bpublic interface A<E> { … }
- Cpublic interface A<E, F> { … }
- Dpublic interface A(E) { … }
71In the following inheritance chain diagram, a method definition in Class_2 can access a public method of Class_1 directly by using the keyword super
Object ← Class_1 ← Class_2 ← Class_3- ATrue
- BFalse
72An abstract declaration may or may not have any abstract method
- ATrue
- BFalse
73In Java, if you define an abstract class called MyClass and extends that class to AnotherClass, you can use the following statement in the main() method
MyClass[] foo = new MyClass[20]- ATrue
- BFalse
74The following interface declaration is NOT valid
public interface MyInterface{
//contains no data field or method
}- ATrue
- BFalse
75The following code will NOT compile. Assume that the interface and the two classes are stored in three different files inside the same package
public class myClass {
public static void main(String[] args) {
myInterface mi = new someClass();
my.printInfo();
}
}
public interface myInterface {
int x = 5;
public void printInfo();
}
public class someClass implements myInterface{
public void printInfo() {
int z = 3;
z = ++x+z;
System.out.println(x);
}
}- ATrue
- BFalse
76The following code will compile
public class Apple extends Fruit {
}
class Fruit {
public Fruit(String name) {
System.out.println(“Fruit’s constructor is invoked”);
}
}- ATrue
- BFalse
77Regarding greedy algorithms, which of the following statements are true (select all that apply)
- AA greedy algorithm tends to be very efficient
- BA greedy algorithm will backtrack when it finds a suboptimal solution
- CA greedy algorithm constructs a solution by choosing the best option at any given moment
- DA greedy algorithm is guaranteed to find the optimal solution
78In dynamic programming, the subproblems are independent of each other
- ATrue
- BFalse
79The algorithm in finding the value from a particular index in a Fibonacci sequence is an example of the following design-concept-based Algorithm
- ADivide and conquer
- BDynamic
- CDecrease and conquer
- DGreedy
- EReduction
80What would be the time-complexity of the following if-else statement?
if (condition)
{Block 1}
else
{Block 2}- AO(n)
- BO(1)
- CO(n^2)
- DNone of the choices are correct
Information
- Description
- bonus quizzes + review questions
- Author
- Jewella Macabenta
- Language
- English
- Views
- 15
- Tags
- Rating
- No ratings yet Rate this quiz