Confusion in line about difference between instance and object in Java context

Can anyone please what is said about instance and object:

If the class is a general representation of an object, an instance of its concrete representation.

I know that concrete means not abstract. So what is really a general idea and a concrete idea ?

+4
source share
5 answers

A car is a general representation that has attributes (wheels, doors, color, etc.) and behavior (starting, stopping, braking, accelerating, changing gears, etc.), also called a class.

Bob Ford Focus (red, license plate number LH 12 233) is an instance of the Car class, also called an object.

+10
source

My best advice is to drop the dictionary. to look for what specific means and how to try to apply the definition to understand what the author had in mind when he or she used a specific representation to describe an instance of an object is simply wrong.

Look for other explanations of what objects, classes, and object instances are, and I'm sure you will find many examples with great examples.

Basically, you can think of a class as a “recipe” or as a “template” (although I don’t want to talk about a template for fear of confusion) and an instance as an “embodiment” of the recipe or template mentioned. therefore, a concrete view.

So, you have the following: class (recipe):

class Human { private string Name; private int Age; public void SayHello() { // run some code to say hello } public Human(string name, int age) { Name = name; Age = age; } } 

And these are instances (objects) ..

  Human mike = new Human("Mike", 28); Human jane = new Human("Jane", 20); Human adam = new Human("Adam", 18); 

These are options or specific representations of our Human class.

+6
source

"General" means "describes what things are, what qualities they share." "Concrete" means "which is especially important for this, which distinguishes it from others of its type."

+1
source

In the context of Java:

Object: This is a class. Instance: a thing created by using a class.

EX: (to use the car example above) In the example below, “Car” is an object, and myInstanceOfCar is an instance.

 class Car private String color; public static void main(String[] args) { Car myInstanceOfCar = new Car(); } } 
+1
source

Classes are in some way, object templates, and class instances are objects. Objects are determined by their type and are “built” using this template, which objects, their properties and methods and all their attributes depend on this template. Think of classes as "mold", as well as objects that come out of these forms.

0
source

All Articles