2
Sponsored Links


Ad by Google
In my previous post, I have listed 20 JSP Servlet interview question. And recently, I went for an interview to collect few interview questions for my friends to post here. The organization is one of the world's well known Banking company. It's a product based company, when I went to their campus almost 200 candidates are their to appeared in interview. And the process was first technical written test following 1st and 2nd round of technical discussion than HR round. Although I have already listed 20 Core java interview question .
In this post, I am going to share the questions asked in written test. The question is objective type and contains 20 question carrying 2 marks each question and passing score was 20. The Questions level is from basic to intermediate.

Question 1. What will be the output of below program?
package com.javamakeuse.poc;

public class Test01 {
 public static int num = 20;

 public static void main(String[] args) {
  Test01 test01 = null;
  System.out.println(test01.num);
 }
}
Question 2. Select the correct answer.
package com.javamakeuse.poc;

public class Test02 {
 public static void m1() {
  try {
   throw new IllegalArgumentException("exce");
  } catch (ArithmeticException e) {
   e.printStackTrace();
  }
 }

 public static void main(String[] args) {
  m1();
 }
}
Option 1. Compile Time Error
Option 2. Run Time error, It will print stack trace containing exce in error message.
Option 3. It will not print anything.

Question 3. What will be the output of this program.
package com.javamakeuse.poc;

public class Test03_2 extends Test03 {

 public Test03_2() {
  System.out.println(super.num);
 }

 public static void main(String[] args) {
  Test03_2 test03_2 = new Test03_2();
 }
}

// another class in the same package
package com.javamakeuse.poc;

public class Test03 {
 private int num = 25;
}
Question 4. What will be the output of this program.
package com.javamakeuse.poc;

public class Test04_C extends Test04_B {
 public static void main(String[] args) {
  Test04_C c = new Test04_C();
  c.m1();
 }
}
package com.javamakeuse.poc;

public class Test04_B extends Test04_A {

}
package com.javamakeuse.poc;

public class Test04_A {
 public void m1() {
  System.out.println("class A");
 }
}
Question 5. What will be the out put of this program.
package com.javamakeuse.poc;

public class Test05_C extends Test05_B {

 public void display() {
  System.out.println("Class C");
 }

 public static void main(String[] args) {
  Test05_C c = new Test05_C();
  Test05_B b = new Test05_B();
  Test05_A a = new Test05_A();
  b = (Test05_B) a;
  c.display();
  b.display();
 }
}
package com.javamakeuse.poc;

public class Test05_B extends Test05_A {

 public void display() {
  System.out.println("Class B");
 }

}
package com.javamakeuse.poc;

public class Test05_A {
 public void display() {
  System.out.println("Class A");
 }
}
Question 6. What will be the out put of this program.
package com.javamakeuse.poc;
public class Test06_C extends Test06_B {
 public void display() {
  System.out.println("Class C");
 }

 public static void main(String[] args) {
  Test06_C c = new Test06_C();
  Test06_B b = c;
  b.display();

 }
}
package com.javamakeuse.poc;

public class Test06_B extends Test06_A {
 public void display() {
  System.out.println("Class B");
 }
}
package com.javamakeuse.poc;

public class Test06_A {
 public void display() {
  System.out.println("Class A");
 }

}
Question 7. What will be the out put of this program.
package com.javamakeuse.poc;
public class Test07_2 extends Test07 {
 public void m2() {
  System.out.println("m2");
 }

 public static void main(String[] args) {
  Test07_2 test = new Test07_2();
  test.m2();
 }
}
package com.javamakeuse.poc;

public final class Test07 {
 public void m1(){
  System.out.println("m1");
 }

}
Question 8. What will be the out put of this program.
package com.javamakeuse.poc;
public class Test08 {
 publicvoid display() {
  System.out.println("display");
 }

 public static void main(String[] args) {
  Test08 test = new Test08();
  test.display();
 }
}
Question 9. What will be the out put of this program.
package com.javamakeuse.poc;
import java.util.Stack;

public class Test09 {

 private static Stack<Integer> intStack = new Stack<>();

 public static void main(String[] args) {
  intStack.push(12);
  intStack.pop();
  System.out.println(intStack.pop());
 }

}
Question 10. What will be the output of this program?.
package com.javamakeuse.poc;
import java.util.TreeMap;

public class Test10 {
 public static TreeMap<String, Integer> tMap = new TreeMap<>();

 public static void main(String[] args) {
  tMap.put("three", 3);
  tMap.put("nine", 9);
  tMap.put("seven", 7);
  tMap.put("one", 1);
  System.out.println(tMap);
 }
}
Question 11. What will be the output of this program?
package com.javamakeuse.poc;
import java.util.TreeMap;

public class Test11 {
 private static TreeMap<Integer, Integer> tMap = new TreeMap<Integer, Integer>();

 public static void main(String[] args) {
  tMap.put(3, 3);
  tMap.put(9, 9);
  tMap.put(5, 5);
  tMap.put(2, 2);
  tMap.put(87, 89);
  tMap.put(25, 25);
  System.out.println(tMap);

 }
}
Question 12. What will be the output of this program?
package com.javamakeuse.poc;

public class Test12 {
 private static int num = 10;

 private int num2 = 10;

 public Test12() {
  num += 10;
  num2 += 10;
 }

 public void m() {
  System.out.println("num in m() - " + num);
  System.out.println("num2 in m() - " + num2);
 }

 public static void main(String[] args) {
  Test12 test1 = new Test12();
  test1.m();
  Test12 test2 = new Test12();
  test2.m();
 }
}
Question 13. What will be the output of this program?
package com.javamakeuse.poc;
public class Test12 {
 private static int num = 10;

 private int num2 = 10;

 public Test12() {
  num += 10;
  num2 += 10;
 }

 public void m() {
  System.out.println("num in m() - " + num);
  System.out.println("num2 in m() - " + num2);
 }

 public static void main(String[] args) {
  Test12 test1 = new Test12();
  test1.m();
  Test12 test2 = new Test12();
  test2.m();
 }
}
Question 14. What will be the output of this program?
package com.javamakeuse.poc;

public class Test14 {
 private int num;
 private static int num2;
 {
  num += 10;
  num2 += 10;
 }
 static {
  num += 10;
  num2 += 10;
 }

 public static void main(String[] args) {
  Test14 test = new Test14();
  System.out.println("num " + test.num);
  System.out.println("num2 - " + num2);
 }
}
Question 15. What will be the output of this program?
package com.javamakeuse.poc;
import java.util.HashSet;
import java.util.Set;

public class Test15 {
 private int id;
 private String value;

 public Test15(int id, String value) {
  this.id = id;
  this.value = value;
 }

 public int getId() {
  return this.id;
 }

 public String getValue() {
  return this.value;
 }

 @Override
 public int hashCode() {
  final int prime = 31;
  int result = 1;
  result = prime * result + id;
  result = prime * result + ((value == null) ? 0 : value.hashCode());
  return result;
 }

 public static void main(String[] args) {
  Set<Test15> set = new HashSet<Test15>();
  Test15 test = new Test15(1, "one");
  Test15 tes2 = new Test15(1, "one");
  set.add(test);
  set.add(tes2);
  System.out.println("Size of set is - " +set.size());

 }
}
Friends, I have not posted the options of all the above question here, but you can give a try on this. Few popular question on the F2F discussion was, Balanced the parenthesis with O(N) order, Why String is immutable in java here and Design your own Array List here.

That's it:) Friends I have shared my interview experienced here, If you wish to share your interview experience than you can share your question/answer in the comments and, than, I will add your inputs to our this blog.
Sponsored Links

2 comments:

  1. Could you please let me know the answer for Question #2?

    ReplyDelete
  2. where are the answers for these questions ?

    ReplyDelete