What does is mean to make an instance of an object? - Java
Does it mean to create/name the array ??? I don't really get it.....
Think of a class in java like a cookie mold, You can make an infinite amount of cookies with that mold. Now think every object created by the class as the cookie. The act of creating any object, is creating an "instance" of the class. You never really create an instant of an object, unless your getting into inheritance.
Or think of an instance as the type, and the instance as a variable of that type. i.e: int i = 3 Your "class" would be int, and your "instance" would be i.
Although the is an Object class in Java that is extended by many other classes, dmelando is right. In OOP you make an instance of a class not of an object, but that instance of a class is an object of that class. Think of it this way: Corvette is a model (class) of car. It has a specific definition (how it is made, what it looks like, how fast it can go, etc). Now I can sit here and talk about the Corvette all day, but all I have is the definition (class). Now, I take that definition and actually make a Corvette. I have now made an instance of the class Corvette and that instance is an object that I can manipulate. The ways that I can manipulate it are defined by the class. In other words, I can make it go forwards and backwards because those are its methods, those functions are in it's class definition, but I cannot make it fly. So for a practical example, let's use the Java class Date since it is simple. Date is a native Java class that you can use to create date and time objects. So for example: DateFormat df = new SimpleDateFormat("MM/dd/yy"); String formattedDate = df.format(new Date()); creates a date object in the format MM/dd/yy, and DateFormat df = new SimpleDateFormat("yyyy/MM/dd"); String formattedDate = df.format(theDate); creates a date object in the format yyyy/MM/dd Now I can use these objects to display the date, calculate a leap year, determine someone's sign after they enter their birth date, etc. And the specific instance of the date object that i make is going to depend on what i am using it for.
Join our real-time social learning platform and learn together with your friends!