We are saying that java is not purely object oriented since primitive data types are not objects.
See the below code:
how object is holding primitive data type?
public class Test{
public Object meth(Object obj){
System.out.println(obj instanceof Object);//It prints true
System.out.println("Value = "+obj);//It prints "Value = 1"
return obj;
}
public static void main(String[] args) {
int a = 1;
System.out.println(new Test().meth(a));
}
}
It's called autoboxing. Basically, the Java compiler converts primitive data types into objects for you when you use them in a context that requires them to be objects.
int are wrapped in a Integer Object.
Conclusion:-
Java is not purely object oriented.
No comments:
Post a Comment