Java Questions Flashcards
Which one of the following is NOT true?
- Java is an Object Oriented language.
- Java has a preprocessor to parse #define, #include type statements.
- Java has no explicit pointer type.
- Java code is portable across platforms.
- JavaScript has no direct relationship to Java.
- Java has a preprocessor to parse #define, #include type statements.
A Java Applet has a main method. True or False?
False
In Java, the closest analogy to a C function is called a/an:
1. attribute
2. class
3. interface
4. method
5. object
- method
Select the correct answer by reviewing the following program.
1 HelloWorld.java: Hello World Application
2 #include java.lang.;
3 public class HelloWorld {
4 public void main(int argv, String args) {
5 System.out.println(“Hello World!”);
6 }
7 }
- Only line 1 is incorrect.
2 Only lines 1 and 5 are incorrect.
3 Only lines 1, 2 and 4 are incorrect.
4 Only lines 2 and 5 are incorrect.
5 Only line 4 is incorrect.
- Only lines 1, 2 and 4 are incorrect.
Which one of the following regarding Java identifiers is incorrect?
1 Must not start with a digit
2 The characters must be letters, digits, or underscore symbols
3 Can be of any length
4 Are not case-sensitive
5 Cannot be Java keywords
- Are not case-sensitive
Which one of the following variable names is the best to choose for a
variable to store the window height in a windowing application?
1 window_height
2 _windowHeight
3 windowHeight
4 w
5 WindowHeight
- windowHeight
Which one of the following is suitable to be used as a Java identifier?
1 System
2 length
3 public
4 class
5 String
- length
Which one of the following statements is incorrect?
1 int is a primitive data type.
2 String is a derived data type.
3 Array is a derived data type.
4 Float is a primitive data type.
5 boolean is a primitive data type.
- Float is a primitive data type.
Which one of the assignment statements is INCORRECT?
1 double a = 2;
2 double b = 2.7;
3 float c = 1.7;
4 double d = 2.70;
5 double e = 2/3;
- float c = 1.7;
Correct assignment: float c = 1.7F
Consider the following variable definitions.
float x = 1.2F; int y = 2; double z = 4.0;
char p = ‘a’; short q = 1;
Which one of the assignment statements is NOT valid?
1 y = q;
2 x = z;
3 x = y;
4 z = y;
5 x = p;
- x = z
byte -> short -> int -> long -> float -> double
char -> int
Which of the following are variable types in Java? You may select more
than one answer.
1 instance variable
2 local variable
3 method variable
4 global variable
5 static variable
1, 2 ,5
What is a local variable in Java?
A variable defined inside a Java method.
Which one of the following declarations is NOT valid?
1 final int MAX_LENGTH = 420;
2 final double PI = 3.1428;
3 final char CHAR_CONST = “Z”;
4 final boolean BOOL_CONST = true;
5 final String STR_CONST = “Hello World”;
(3) final char CHAR_CONST = “Z”;
Consider the following Java program.
1 class CompareNumbers {
2 public static void main(String args[]) {
3 int a = 20, b = 10;
4 boolean c = 0;
5 if (a < b) c = 1;
6 System.out.println(“c = “ + c);
7 }
8 }
Which one of the following is correct?
1 The output will be: c = 0
2 The output will be: c = 1
3 The program will have a compilation error.
4 The program will have a run-time error.
- The program will have a compilation error.
Consider the following Java program.
1 class TwoWayExample {
2 public static void main(String args[]) {
3 int a = 20;
4 boolean b;
5 b = (a < 10) ? true : false;
6 System.out.println(“b = “ + b);
7 }
8 }
Which one of the following is correct?
1 The output will be: b = true
2 The output will be: b = false
3 The program will have a compilation error.
4 The program will have a run-time error.
- The output will be: b = false