Language Fundamentals Questions
Practice Language Fundamentals MCQs with answers and explanations. Page 1 of 2.
Category
Java Programming
Topic
Language Fundamentals
Page
1 / 2
Mode
Practice
Questions
Open any question to view the answer and explanation.
Java — In an interface, which explicit declarations are equivalent to the implicit constant defined on line 3?
Given:
public interface Foo {
int k = 4; // Line 3
}
Pick the three equivalent explicit forms.
Open
View answer
Java — Which declarations are valid inside an interface definition?
Open
View answer
Java — Which one is a valid boolean variable declaration and initialization?
Open
View answer
Java — What is the numerical range of a char (primitive type)?
Open
View answer
In Java programming, which of the following is a valid declaration of a String variable?
Open
View answer
Which of the following is a valid Java keyword (reserved word) recognized by the Java compiler?
Open
View answer
In Java, which option both declares an int array and initializes it immediately with five specific numbers?
Open
View answer
In Java, which three are valid declarations for a float variable among the following candidates?
Open
View answer
Which of the following is a reserved Java keyword (cannot be used as an identifier)?
Open
View answer
In Java, which three of the following are valid char declarations or assignments?
Open
View answer
Java arrays default values: which four entries correctly describe default element values for the given types?
Open
View answer
Which one of the following lists contains only valid Java language keywords (no identifiers or non-Java tokens)?
Open
View answer
In Java, which three are legal array declarations among the following?
Open
View answer
Which statement legally declares, constructs, and initializes a one-dimensional int array in Java?
Open
View answer
Java arrays and command-line arguments: trace the output when copying args into a 2D array reference.
public class CommandArgsThree {
public static void main(String[] args) {
String[][] argCopy = new String[2][2];
int x;
argCopy[0] = args; // first row refers to args array
x = argCopy[0].length;
for (int y = 0; y < x; y++) {
System.out.print(" " + argCopy[0][y]);
}
}
}
// Invocation: > java CommandArgsThree 1 2 3
Open
View answer
Java arrays and command-line arguments: populating a larger array from args and printing names[2].
public class X {
public static void main(String[] args) {
String[] names = new String[5];
for (int x = 0; x < args.length; x++)
names[x] = args[x];
System.out.println(names[2]);
}
}
// Invocation: > java X a b
Open
View answer
Java entry point rules: what happens when main is not declared static?
public class F0091 {
public void main(String[] args) {
System.out.println("Hello" + args[0]);
}
}
// Command line: > java F0091 world
Open
View answer
Java command-line arguments and array bounds: trace the loop and identify the runtime behavior.
public class CommandArgsTwo {
public static void main(String[] argh) {
int x;
x = argh.length; // number of arguments
for (int y = 1; y <= x; y++) {
System.out.print(" " + argh[y]); // note: starts at 1 and uses <=
}
}
}
// Invocation: > java CommandArgsTwo 1 2 3
Open
View answer
Java multidimensional arrays (jagged): accessing an uninitialized inner array element.
public class TestDogs {
public static void main(String[] args) {
Dog[][] theDogs = new Dog[3][]; // only outer dimension allocated
System.out.println(theDogs[2][0].toString());
}
}
class Dog { }
Open
View answer
Java keywords and for-loop tracing: identify the compile-time outcome of using “signed”.
public class Test {
public static void main(String[] args) {
signed int x = 10;
for (int y = 0; y < 5; y++, x--)
System.out.print(x + ", ");
}
}
Open
View answer
Practice smarter
Solve a few questions daily and revisit weak topics regularly to improve accuracy.