-1

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.

Ter Bino
  • 37
  • 4
  • Objects are an instance of a class. A class is a template, a description of the characteristics and behaviour of something. An object is an specific case of that something. Both of your examples are static methods being called. Normally, methods must be called on an instance of a class (that is to say, on an object). Static methods can be called without instantiating a class, as they represent behaviour common to all possible instances of a class. – JustAnotherDeveloper Oct 19 '21 at 16:26
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Oct 19 '21 at 16:45

1 Answers1

0

"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.

Sotirios Delimanolis
  • 274,122
  • 60
  • 696
  • 724