Exam Questions and CORRECT Answers
int age = 3;
String fname = "bob";
String lname = "smith";
int inches = 67;
System.out.printf("Mr. %s (first name %s) is %d inches tall and %d years old", lname, fname,
inches, age);
Mr. smith (first name bob) is 67 inches tall and 3 years old
Mr. bob (first name smith) is 67 inches tall and 3 years old
Mr. smith (first name bob) is 3 inches tall and 67 years old
Mr. bob (first name smith) is 3 inches tall and 67 years old
None of the answers - CORRECT ANSWER - Mr. smith (first name bob) is 67 inches tall
and 3 years old
In Java, the mechanism by which a subclass provides a specific implementation of a method that
is already defined in its superclass is known as
Encapsulation
Polymorphism
Inheritance
Method overriding
Abstraction - CORRECT ANSWER - Method overriding
The process of rearranging the elements of an array in a specific order (e.g., ascending or
descending) is known as
,Shuffling
Sorting
Searching
Filtering
None of the answers - CORRECT ANSWER - Sorting
Which of the following would correctly declare and instantiate an array of 3 String elements?
String[] names = new String[2];
String names[] = new String[3];
String[] names = new String[4];
String names = new String[3];
String[3] names = new String[];
String[] names = new String[];
String names[] = new String[];
String[3] names = new String[3];
String[] names = new String[3];
String[3] names = new String[3]; - CORRECT ANSWER - String names[] = new
String[3];
String[] names = new String[3];
If a primitive type variable is not explicitly initialized, it will store _____.
A default value based on its type
A random value
A null reference
An error
None of the answers - CORRECT ANSWER - A default value based on its type
, class Main {
public static void foo() {
x = 4;
}
public static int x = 12;
public static void main(String[] args) {
int x = 24; foo();
System.out.println(x);
}
} - CORRECT ANSWER - 24
import java.util.ArrayList;
public class OutputQuestion2 {
public static void main(String[] args) {
ArrayList<String> colors = new ArrayList<>();
colors.add("Red");
colors.add("Green");
colors.add("Blue");
colors.remove("Green");
System.out.println(colors);
}
}
[Red, Green, Blue]
[Red, Blue]
[Green, Blue]
[Blue, Red] - CORRECT ANSWER - [Red, Blue]