I kept on searching for answers about this and I am unfortunate.
I'm just a little confused as my professor is teaching me something that contradicts what I learned from online.
Integer, Double, Float, Character etc. are wrapper 'Classes' from what I know. Yet, my college professor keep referring to it as Object. May I also include that he calls Math an object too.
Here's some example on how he says it:
"To get the absolute value of an int, we need to call the abs() method from Math object"
or
"In Integer.parseInt(), Integer is an object while parseInt() is the method."
So, can Wrapper classes be referred to as objects?
Sorry if this is supposed to be something easy to understand. I'm just confused 'cause iirc those he referred to as objects are called Classes.
CodePudding user response:
"Objects" usually refers to instances of classes but sometimes the terms classes and objects are used interchangeably so that might be what is happening here with your professor. There are Integer, Float, etc, classes which you can instantiate to make Integer, float, etc objects. So for example:
Integer num = new Integer(5); //"Integer" is the class and you are instantiating that class to make an Integer object called "num"
int n = Integer.parseInt("5"); //"Integer" is the class and you are calling the static method of that class "parseInt" which returns an int
The Math class is a class that you cannot instantiate because it doesn't have a constructor. It just has static methods that you can call. Since you can't instantiate it as an object it is not technically proper to refer to it as an object.