public class Container1{
private Object obj;
public Container1(Object obj){
this.obj=obj;
}
public Object getobj(){
return this.obj;
}
public void showType(){
System.out.println("Type is "+obj.getClass().getName());
}
public static void main(String[] args)
{
Container1 c1=new Container1("deva");
String s1=(String)c1.getobj();
System.out.println("String is "+s1);
c1.showType();
Container1 c2=new Container1(123);
Integer s2=(Integer)c2.getobj();
System.out.println("Integer is "+s2);
c2.showType();
}
}
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter