26-05-2012, 10:03 AM
Self-test Java Programming Questions
QUESTIONS SELFTEST JAVA PROGRAMMING.pdf (Size: 42.98 KB / Downloads: 84)
1. Which of the following statements about arrays is syntactically wrong?
O (a) Person[] p = new Person[5];
O (b) Person[5] p;
O © Person[] p [];
O (d) Person p[][] = new Person[2][];
2. Given the following piece of code:
public class Test {
public static void main(String args[]) {
int i = 0, j = 5 ;
for( ; (i < 3) && (j++ < 10) ; i++ ) {
System.out.print(" " + i + " " + j );
}
System.out.print(" " + i + " " + j );
}
}
what will be the result?
O (a) 0 6 1 7 2 8 3 8
O (b) 0 6 1 7 2 8 3 9
O © 0 5 1 5 2 5 3 5
O (d) compilation fails
3. Which of the following declarations is correct? (2 answers):
[_] [a] boolean b = TRUE;
[_] [b] byte b = 255;
[_] [c] String s = “null”;
[_] [d] int i = new Integer(“56”);
4. Suppose a class has public visibility. In this class we define a protected method. Which of the
following statements is correct?
O (a) This method is only accessible from inside the class itself and from inside all subclasses.
O (b) In a class, you can not declare methods with a lower visibility than the visibility of the class
in which it is defined.
O © From within protected methods you do not have access to public methods.
O (d) This method is accessible from within the class itself and from within all classes defined
in the same package as the class itself.
11/12/2009 Self-test Java Programming 4
5. Given the following piece of code:
public class Company{
public abstract double calculateSalaries();
}
which of the following statements is true?
O (a) The keywords public and abstract can not be used together.
O (b) The method calculateSalaries() in class Company must have a body
O © You must add a return statement in method calculateSalaries().
O (d) Class Company must be defined abstract.
6. Given the following piece of code:
public interface Guard{
void doYourJob();
}
abstract public class Dog implements Guard{}
which of the following statements is correct?
O (a) This code will not compile, because method doYourJob() in interface Guard must be
defined abstract.
O (b) This code will not compile, because class Dog must implement method doYourJob()
from interface Guard.
O © This code will not compile, because in the declaration of class Dog we must use the keyword
extends in stead of implements.
O (d) This code will compile without any errors.