Thursday, December 25, 2008

1.Class C {
public static void main(String[] args) {
int[]a1[]=new int[3][3]; //3
int a2[4]={3,4,5,6}; //4
int a2[5]; //5
}}
What is the result of attempting to compile and run the program ?.
1.compiletime error at lines 3,4,5
2.compiltime error at line 4,5
3.compiletime error at line 3
4.Runtime Exception
5.None of the above
Ans: 2
Explanation:
no value shoud be specified in the rightsidebrackets when constructing an array
2. interface I{
void f1(); // 1
public void f2(); // 2
protected void f3(); // 3
private void f4(); // 4
}
which lines generate compile time errors?
1.compiletime error at lines 1,2,3,4
2.compiletime error at line 3
3.compiletime error at line 1
4.compiletime error at lines 3,4
5.None of the above
Answer: 4
Explanation:
all methods declared within an interface are implicitly public, a weaker access level can not be declared.
3)
class C{
int i;
public static void main (String[] args) {
int i; //1
private int a = 1; //2
protected int b = 1; //3
public int c = 1; //4
System.out.println(a+b+c); //5
}}
1.compiletime error at lines 1,2,3,4,5
2 compiletime error at lines 2,3,4,5
3.compiletime error at lines 2,3,4
4.prints 3
5.None of the above
Answer 2
Explanation:
The access modifiers public, protected and private, can not be applied to variables declared inside methods.

No comments: