Saturday, March 19, 2011

1. a b c d g i j k
byte short int long float double boolean char

2. d
Compile error at line 18
Both class A and B are declared in the same package.
Therefore, class B has access to the public, protected, and package access methods of class A.

3. b
Prints: BCD
The index for the first element of an array is zero.
Question 1

Which of these words belong to the set of java key words.
  1. byte
  2. short
  3. int 
  4. long
  5. decimal
  6. int64
  7. float
  8. single
  9. double
  10. boolean
  11. char
  12. unsigned
  13. array
  14. string
  15. None of the above
Question2
  1.  package com.dan.chisholm;
  2. public class A {
  3.    public void m1() {
  4.       System.out.println("A.m1, "); }
  5.    protected void m2() {
  6.       System.out.println("A.m2, "); }
  7.    private void m3() {
  8.       System.out.println("A.m3, "); }
  9.     void m4(){
  10.        System.out.println("A.m4, "); }
  11. }

  12. class B {
  13.     public static void main(String args[]){
  14.           A a = new A();
  15.           a.m1(); 
  16.           a.m2();
  17.           a.m3();
  18.           a.m4();
  19.    }
  20. }
Assume that the above code appears in a single file named A.java. What is the result of attempting to compile and run the above program?
  1. Prints A.m1, A.m2, A.m3, A.m3, A.m4,
  2. Compiler error at line 16
  3. Compiler error at line 17
  4. Compiler error at line 18
  5. Compiler error at line 19
  6. None of the above.
Question 3

class Violet {
  public static void main(String s[]){
     System.out.println(s[1]+s[2]+s[3]);
  }
}

Assume the above main method is invoked using the following command line.

java Violet A B C D E F

What is the result of attempting to compile and run the program using the specific command line?
  1. Prints: ABC
  2. Prints: BCD
  3. Prints: CDE
  4. Prints: ABC
  5. Prints: BCD
  6. Prints: CDE
  7. Compile Error
  8. Run time Exception
  9. None of the above