Tuesday, March 3, 2015

Autoboxing and Autounboxing

Autoboxing is the process of converting the primitive type to Wrapper type(object) and unboxing is the vice versa .Below example illustrate the same.

package autobox;

public class AutoBoxExample {

 public static void main(String[] args) {
  // TODO Auto-generated method stub
  int i=10;
  Integer i1=new Integer(i);//boxing
  Integer i2=20;//boxing
  int i3=i2;//unboxing
  System.out.println(i1);
 }

}

output:
10 >>>Final
------------------------------------------------------------------------------------------------------------

Interfaces

Interface is used to attain 100% abstraction.
-- Interface contains only the definition and not the implementation.
-- interface by default attach variable (public static final) and for method it is (public and abstract)
-- interface can extends any number of interfaces and class can implement any number of interfaces.
-- The rule is it must override all the methods defined in the interface else it needs to be defined as abstract.


------

>>>Final
------------------------------------------------------------------------------------------------------------