10 Tricky Core Java Interview Coding - TopicsExpress



          

10 Tricky Core Java Interview Coding Questions. ------------------------------------------------------------------ 1) Can you instantiate this class? public class A { A a = new A(); } 2) Is the below code written correctly? If yes, what will be the output? class A { static void staticMethod() { System.out.println(Static Method); } } public class MainClass { public static void main(String[] args) { A a = null; a.staticMethod(); } } 3) What will be the output of the following program? class A { static int i = 1111; static { i = i-- - --i; } { i = i++ + ++i; } } class B extends A { static { i = --i - i--; } { i = ++i + i++; } } public class MainClass { public static void main(String[] args) { B b = new B(); System.out.println(b.i); } } 4) What happens when you call methodOfA() in the below class? class A { int methodOfA() { return (true ? null : 0); } } 5) What will be the output of the below program? public class MainClass { public static void main(String[] args) { Integer i1 = 127; Integer i2 = 127; System.out.println(i1 == i2); Integer i3 = 128; Integer i4 = 128; System.out.println(i3 == i4); } } 6) Can we override method(int) as method(Integer) like in the below example? class A { void method(int i) { //method(int) } } class B extends A { @Override void method(Integer i) { //method(Integer) } } 7) Which statements in the below class shows compile time error (Line 5 or Line 7 or both)? public class MainClass { public static void main(String[] args) { Integer i = new Integer(null); String s = new String(null); } } 8) What will be the output of the following program? public class MainClass { public static void main(String[] args) { String s = ONE+1+2+TWO+THREE+3+4+FOUR+FIVE+5; System.out.println(s); } } 9) What will be the output of the below program? public class MainClass { static int methodOne(int i) { return methodTwo(i *= 11); } static int methodTwo(int i) { return methodThree(i /= 11); } static int methodThree(int i) { return methodFour(i -= 11); } static int methodFour(int i) { return i += 11; } public static void main(String[] args) { System.out.println(methodOne(11)); } } 10) What will be the output of the following program? public class MainClass { public static void main(String[] args) { int i = 10 + + 11 - - 12 + + 13 - - 14 + + 15; System.out.println(i); } } See the answers at : javaconceptoftheday/tricky-core-java-interview-coding-questions/
Posted on: Mon, 19 Jan 2015 04:58:43 +0000

Trending Topics



Recently Viewed Topics




© 2015