Saturday 24 October 2015

British Telecom Written Test - Aptitude + Java

British Telecom Written Test

British Telecom
Aptitude - 25 Question in 25 mins
20 questions were data interpretation, example question below-
The one was from CAT 2007

Solution



Java - 35 Questions in 35 mins
10 of them being multiple answer type with 5 options. Below are a few sample questions I can remember.

Q1 Select all the methods of Thread class that are static.
1. yield()
2. sleep()
3. wait()
4. run()
5. join()

Q2 Select all the valid declaration for interface.
1.
interface Test {
    public int a = 100;
    public void test() throws RuntimeException;
}

2.
abstract interface Test {
    public int a = 100;
    public void test() throws RuntimeException;
}

3. interface Test {
    public int a = 100;
    public void test();
}
Some more options i don't recall. All the above are valid declaration.

Q3 Conside the following declaration.
class Tyre {
    public void front() throws RuntimeException {
        System.out.println("Tire");
    }

    public void front(long a) {
        System.out.println("Radial Tire with long");
    }
}



class RadialTyre extends Tyre {
    public void front() {
        System.out.println("Radial Tire");
    }
    public void front(int a) throws RuntimeException {
        System.out.println("Radial Tire with int");
    }
}

public static void main(String... args) {
        Tyre t = new RadialTyre();
        int a = 10;
        t.front(a);

}
Select the correct output.
1. Radial Tyre Radial Tire with long
2. Radial Tyre Radial Tire with int
3. Tire Radial Tire with long
4. Tire Radial Tire with int

Q4 Using the declaration of question 3, consider the following the select the correct option.
public static void main(String... args) {
         System.out.println("This is just a test");
         Tyre t = new RadialTyre();
         Tyre t1 = new Tyre();
         RadialTyre r = new RadialTyre();

         System.out.println(Tyre instanceof t1);      //Line 1
         System.out.println(t1 instanceof RadialTyre);        //Line 2
         System.out.println(Tyre instanceof r);        //Line 3
         System.out.println(r instanceof RadialTyre);        //Line 4
}

1. True False True True
2. False False True True
3. True True True True
4. Compile Time error at line 1 and 3
5. Compile Timer error at line 2 and 4


Q5 Consider the following program
public static void main(String... args) { 
        Set nodeSet = new HashSet();
        nodeSet.add(new Node(10));
        nodeSet.add(new Node(20));
        nodeSet.add(new Node(30));
        nodeSet.add(new Node(10));
        nodeSet.add(new Node(20));

        System.out.println(nodeSet.size()); 
}
Select the correct output-
1. 5    2. 3   3. Compile Time Error    4. RunTimeException


Q6 Consider the following program
    public static void main(String... args) {
        List list = new ArrayList();
        list.add(new Node(10));
        list.add(new String("Harsh"));

        System.out.println(list.get(1)); 
}
Select the correct output-1. 10     2. Harsh     3. CompileTimeError     4. CastClassException

Note: Correct answer is in bold
Comment below if you find this useful. This is just for reference and making up you mind.

24 comments :

  1. Hi Anshul have u attended the test please let me know the type of question .

    ReplyDelete
  2. Answer to question no.4 is wrong
    It should be option 4. Compile Time error at line 1 and 3

    ReplyDelete
  3. answer to que5 is wrong , FOr Hashset the ans will be 3 , it will take duplicate values.

    ReplyDelete
    Replies
    1. sorry , it will not take duplicate values .

      Delete
    2. If you look closely..

      their is NO duplication happening while creating object of class "Node" using new keyword. Every time a separate object is getting created. Therefore answer:5

      Delete
    3. This comment has been removed by the author.

      Delete
  4. Answer to the fifth question is option 2.

    ReplyDelete
    Replies
    1. option 1 is the correct answer, it will be option 2 if you override hashcode and equals

      Delete
    2. Why think, when you can try. I tried, the answer came to option 2, as Oracle has ensured that you do not fool the add method into increasing size, even if you are adding duplicate values

      Delete
    3. I think u tried by using Integer or String instead of node. Answer came 5 when i used a nested node class .

      Here is the code
      :-

      package exp;

      import java.util.HashSet;
      import java.util.Set;

      public class Main {

      private static class node{

      private int i ;
      public node(int i ){
      this.i = i ;
      }
      }

      public static void main(String[] args) {
      Set nodeSet = new HashSet();
      nodeSet.add(new node(10));
      nodeSet.add(new node(20));
      nodeSet.add(new node(30));
      nodeSet.add(new node(10));
      nodeSet.add(new node(20)); //

      System.out.println(nodeSet.size());
      }


      }

      Delete
  5. could you post more questions if possible

    ReplyDelete
  6. Very help ful. these snippets are.Thanks man.

    ReplyDelete
  7. Can someone pls explain the third ques in brief

    ReplyDelete
    Replies
    1. This comment has been removed by the author.

      Delete
    2. In overloading, method resolution takes care by compiler based on reference type.
      Since it's a overloading method call, the Tyre class(Parent class) method will be called here.

      P.S. In Overriding, method resolution takes care by JVM based on runtime object which is nothing but Radial Tyre(child class).
      but in our example it's overloading not the overriding.

      Delete
  8. Replies
    1. Can you please post more aptitude questions, if you remember.

      Delete
  9. Thanks for the questions helped me a lot...

    ReplyDelete
  10. Replies
    1. Can you please post more aptitude questions, if you remember.

      Delete