Java Questions And Answers IV

Q. 2
What is the correct ordering for the import, class and package declarations when found in a single file?
A.  package, import, class
B.  class, import, package
C.  import, package, class
D.  package, class, import
Select the most appropriate answer.
A.

Q. 3
Which methods can be legally applied to a string object?
A.  equals(String)
B.  equals(Object)
C.  trim()
D.  round()
E.   toString()
Select all correct answers.
A, B, C, E,
Q. 4
What is the parameter specification for the public static void main method?
A.  String args []
B.  String [] args
C.  Strings args []
D.  String args
Select all correct answers.
A,B


Q.5
What does the zeroth element of the string array passed to the public static void main method contain?
A.  The name of the program
B.  The number of arguments
C.  The first argument if one is present
Select the most appropriate answer.
C
Q. 6
Which of the following are Java keywords?
A.  goto
B.  malloc
C.  extends
D.  FALSE
Select all correct answers
A, C
Q. 7
What will be the result of compiling the following code:

public class Test {
public static void main (String args []) {
int age;
age = age + 1;
System.out.println("The age is " + age);
}
}

A.  Compiles and runs with no output
B.  Compiles and runs printing out The age is 1
C.  Compiles but generates a runtime error
D.  Does not compile
E.   Compiles but generates a compile time error
Select the most appropriate answer.
D
Q. 8
Which of these is the correct format to use to create the literal char value a?
A.  ‘a’
B.  "a"
C.  new Character(a)
D.  \000a
Select the most appropriate answer.
A

Q. 9
What is the legal range of a byte integral type?
A.  0 - 65, 535
B.  (–128) – 127
C.  (–32,768) – 32,767
D.  (–256) – 255
Select the most appropriate answer.
B
Q. 10
Which of the following is illegal?
A.  int i = 32;
B.  float f = 45.0; //float f=45.0f
C.  double d = 45.0;
B

Select the most appropriate answer.
Q. 11
What will be the result of compiling the following code:

public class Test {
static int age;
public static void main (String args []) {
age = age + 1;
System.out.println("The age is " + age);
}
}

A.  Compiles and runs with no output
B.  Compiles and runs printing out The age is 1
C.  Compiles but generates a runtime error
D.  Does not compile
E.   Compiles but generates a compile time error
Select the most appropriate answer.

B
Q. 13
Which of the following return true?
A.  "john" == "john"
B.  "john".equals("john")
C.  "john" = "john"
D.  "john".equals(new Button("john"))
Select all correct answers.
AB


Q. 16
Which of the following are acceptable?
A.  Object o = new Button("A");
B.  Boolean flag = true;
C.  Panel p = new Frame();
D.  Frame f = new Panel();
E.  Panel p = new Applet();

A, E
Select all correct answers.
Q. 17
What is the result of compiling and running the following code:

public class Test {
static int total = 10;
public static void main (String args []) {
new Test();
}
public Test () {
System.out.println("In test");
System.out.println(this);
int temp = this.total;
if (temp > 5) {
System.out.println(temp);
}
}
}


A.  The class will not compile
B.  The compiler reports and error at line 2
C.  The compiler reports an error at line 9
D.  The value 10 is one of the elements printed to the standard output
E.   The class compiles but generates a runtime error
D
18.Which of the following is correct:
A.  String temp [] = new String {"j" "a" "z"};
B.  String temp [] = { "j " " b" "c"};
C.  String temp = {"a", "b", "c"};
D.  String temp [] = {"a", "b", "c"};

D

Select the most appropriate answer.

Q. 19
What is the correct declaration of an abstract method that is intended to be public:
A.  public abstract void add();
B.  public abstract void add() {}
C.  public abstract add();
D.  public virtual add();
Select the most appropriate answer
A
1. B
2. A
3. A, B, C, E
4. A, B
5. C
6. A, C
7. D
8. A
9. B
10. B
11. B
12. A,B
13. A, B
14. A, B, C, D
15.B, C
16. A, E
17. D
18. D
19. A
20. B
21. B
22. A, C, D, E
23. B
24. A
25. C
26. A
27. C
28. B
29. A, B, C
30. C
31. C
32. A
33. B
34. A, B, C, D
35. new TextField("hello", 10)
36. A, B, C
37. B
38. D
39. B
40. A
41. A
42. D
43. C
44. B
45. B
46. B
47. A, E
48. B
49. C
50. C
51. F
52. A
53. F
54. C
55. D
56. D, F
57. F
58. A, E
59. A
60. C
61. C
62. A
63. F
64. B
65. C