Sunday, March 4, 2012

Nokia Written Test Question

What is the output of following code:

public class ThreadTest1 implements Runnable{

    public static void main(String args[])throws Exception{

        Thread t1 = new Thread(new ThreadTest1());

        t1.start();
        System.out.println("Begin");
        t1.join();
        System.out.println("End");
    }

    public void run(){
        System.out.println("Run");
    }
}

Nokia Interview Written Test and Questions

Class C extends B and B extends A and how can I directly access a method of A from class C without creating an instance of A.

Options:

1. super.test()
2. super.super.test()
3. There is no way we can access the class A method without creating an instance from class C.

Answer is 3

Here is the example code (they are not given this code, I only wrote for understanding clearly)



1. class A{
    public A(){
        System.out.println("A");   
    }
    public void test(){
        System.out.println("test method of A");
    }

}
class B extends A{
    public B(){
        System.out.println("B");   
    }
    public void test(){
        System.out.println("test method of B");
    }

}

class C extends B{
    public C(){
               System.out.println("C");   
    }

    public void test(){
        System.out.println("test method of C");
    }


}


public class SuperKeyWord{
    public static void main(String args[]){
        C c = new C();
    }
}


Question 2:
Write an immutable java class example.

Question 3:
Write a java program to reverse a given string.

Question 4:
Choose all right answers from the below options.

     a. public synchronized(this) void test(){}
     b. public void test(){ synchronized(Test.class){}}
     c. public void test(){ synchronized(a) {}}
     d. public synchronized void test {}
     e. public void test{ synchronized(this) {}}

EMC Interview Question


package com.example.time.complexity;
/*Question:
 * An integer array of 5 length has some values, while traversing
 * the array multiply all other(except the current element's value)
 * array elements values and place the result  in the current array
 * element
 *
 *    ex: a[] = {11,23,35,41,2}
 *    first traverse a[0]=2x3x4x5
 *    second traverse a[1]=1x3x4x5
 *    third traverse a[2]=1x2x4x5
 *    fourth traverse a[3]=1x2x3x5
 *    fifth traverse a[4]=1x2x3x4
 */
public class ComplexityTest1 {

    public static void main(String args[]){
        int[] i = {11,23,35,41,2};
        int[] res = new int[i.length];
        int len =i.length;
        int temp=1;
        for(int x=0;x<len;x++){
            if(x+1==len){
                temp=1;
            }else{
                temp=i[x+1];
            }
               
            for(int y=0;y<len;y++){
                if(x!=y && (x+1)!=y){
                    //System.out.println(x+"."+temp+"x"+i[y]+"="+(temp*i[y]));
                    temp = temp*i[y];
                }
            }
            res[x]=temp;
        }
        for(int x=0;x<len;x++){
            System.out.println(res[x]);
        }
    }
}