- What is the Java Virtual Machine?
a. A hardware manufactured by SUN Microsystems, Inc.
b. A software
c. A device like chip embedded in the computer harddisk
d. An application
- A program written in the Java programming language can run on any computer because
the Java Virtual Machine interprets the program for the native operating system.
a. True
b. False
- Which of the following are Java keywords or reserved words?
a. New b. break c. Switch d. size
e. length f. friendly g. cast h. operator
i. args j. future k. array l. Integer
- Which of the following are Java primitive types?
a. Boolean b. char c. String d. int
e. float f. double g. Long h. short
- What is the purpose of the main() method?
a. To hold the APIs of the application
b. To create buttons and scrollbars
c. To act as the entry point for the program
- Which of the following are legal statements?
a. float f1 = 1.0/5;
b. int i = 1/5;
c. float f2 = 0.4f;
d. long l = 999D;
- Which of the following are valid statements?
a. int i = 2 + '2';
b. byte b = 123;
c. double d = "5";
d. String s = 't';
- What will happen when you compile and run the following code?
class Hello {
public static void main(String[] args) {
String s;
String s2 = "Alfa";
System.out.println("Hello " + s + s2);
}
}
a. You will get compile-time error.
b. You will get "Hello null Alfa" on the screen.
c. You will get "Hello Alfa" on the screen.
d. You will compile and run it successfully
- Which of the following are valid methods?
a. public static void aMethod() {}
b. void static aMethod() {}
c. public private void aMethod() {}
d. private aMethod() {}
- Which of the following are constructors?
1. class Base {
2. int num;
3. Base() {}
4.
6. public Base(int i) {
7. this.num = i;
8. }
9.
10. public void base() {}
11. void base(int i) {}
12. }
a. Line 3 and 6 are constructors
b. Line 10 and 11 are constructors
c. There are no constructors in this class
d. There are two constructors in this class
- Which of the following are instance variables.
1. class Bar {
2. int num;
3. double amt;
4. static char ch = 'a';
5. Bar() {}
6. void save(int num) {}
7. double withdraw(double amt) {}
8. }
a. line 2 num
b. line 7 amt
c. line 3 amt
d. line 4 ch
e. line 6 num