Posts

Showing posts from April, 2017

Java Interview Question

1. What will be the output final int i = 10; i++; System.out.println(i); Answer: Get compilation Error. You cannot reinitialize the final value. 2. Will the code compile final List<String> list = new ArrayList<String>(); list.add("e"); Answer: Yes, code will compile. list reference is final but we can add a member of it. 3.immutable Properties ◦The instance variable of the class is final i.e. we cannot change the value of it after creating an object. ◦The class is final so we cannot create the subclass. ◦There is no setter methods i.e. we have no option to change the value of the instance variable. 4. Will the code Compile  class Base{   private void get(){    System.out.println("base A");   }  }  class Derive extends Base{   void get(){    System.out.println("deri ");   }  } Answer: Code will compile. Derive class get method consider as method. Hence It accept 4.1 Will the code Compile  class Base{   public b