Interview posts

This page is dedicated , for java Questions for interviews , that is posted on every Monday , and answers are posted on the corresponding friday.

Hi Guys, we are seriously pleased with your response this week . It is definitely an inspiration , to continue our work. Let us spread the wonder of Java.

Post your answers as Comments.


Questions:

Date : 08/02/2010
1) Which are the default access types of Interface variables in Java ?

Related Question from a popular training material for SCJP:

public interface Status {
/* insert code here */ int MY_VALUE = 10;
}



Which are the identifiers allowed ?
A. final
B. static
C. native
D. public
E. private
F. abstract
G. protected

2 ) A good variation of an array passing mechanism in Java :
/* Test Question */

public class test{
  public static void main(String [] args){
        int [] x = new int[10];
        test t = new test();
        t.foo(10,x);

}

void foo(int y,int... x){
}

}/* End Class Declaration */

Well this declaration , does have it's own glitches . The array variable , must be the last argument in the function definition. Other than that it is quite handy.

3) What is the output of the followong code Snippet ??
class printTest{
    public static void main( String [] args){
    System.out.println(System.out.println("Hi testing System.out"));
}
}

4) Predict the output of the following Code Snippet .
    public class Test {
      public static void main(String [] args) {
        int x =5;
        boolean b1 = true;
        boolean b2 = false;

       if((x==4) && !b2)
        System.out.print(”l “);
        System.out.print(”2 “);
          if ((b2 = true) && b1)
          System.out.print(”3 “);
 }
}

5) Under what circumstances is the finally block executed ?    

31. // some code here
32. try {
33. // some code here
34. } catch (SomeException se) {
35. // some code here
36. } finally {
37. // some code here
38. }


A. The instance gets garbage collected.
B. The code on line 33 throws an exception.
C. The code on line 35 throws an exception.
D. The code on line 31 throws an exception.
E. The code on line 33 executes successfully.

Answers shall be posted on friday , the 12 th february.

Wishing you a happy java Testing time!!!!!!
Feel free to comment.


Thank you for your wonderful response to the blog we have moved upto a family of 22 bloggers. This is the interview questions for 14th Feb.

Q1) interface Foo {}
 class Alpha implements Foo { }
 class Beta extends Alpha {}
 class Inherit extends Beta {
 public static void main( String[] args) {
 Beta x = new Beta();
 // insert code here
 }
 }

Which of the following lines , will raise a Class Cast Exception ?
1) Alpha a = x;
2) Foo f = (Inherit)x;
3) Foo f= (Alpha)x;
4) Beta b = (Beta)(Alpha)x;

Q2) A simple analytical pattern recognition question :

11, 17 ,18 , 22 , 25 , 27 , 32 , 32 ,..
Find the next 2 elements in the series .

Q3)  Decode the following statement :

Dpejoh jt qtsf gvo.

Q4) Consider , we have a cocunut tree ,which is 60 feet tall . A monkey wishes to climb it for having some tender coconuts on a hot afternoon. For every 4 feet , the monkey climbs in 1min it descends 2 feet in 1 min . Find the time taken to climb the tree.

Q5) A beautiful C puzzle :

main(){
int i=1;
switch(i)
{
  case 1:   printf("In case 1");
  case 2:   printf("\n In case 2");
            break;
  case 3:   printf("In case 3");
            break;
  default : printf("\nIn default\n");

}
}


Predict the output of the following program and why ??

Posted by :

Jayanthi GM(Course Instructor Java, PESIT)
Prashanth Raghu ( Student Assistant )

Comment on them as your answers .