+ 13
[ Instance Members vs. Static Members: ]
âą https://marcus-biel.com/packages-import-statements/
In the example below we have created the Person class, and within that class we have an instance variable called 'personName' and an instance method called helloWorld(). Our variables and methods are called the 'instance members' of the class.
public class Person {
private Name personName;
public String helloWorld() {
return "Hello World";
}
}
An instance is a single occurrence of an object. While there is only one class, there are many instances of the class: objects.
For example, we can have hundreds and hundreds of different Person objects. Each Person object has its own instance of the personName object, each with its own value and its own version of the helloWorld() method.
+ 3
Just to be clear as my buddy Danijel IvanoviÄ mentioned which it's a great reply btw.
Variables inside a class that are outside a method are called instance variables, but also creating an object of this class using the new keyword is also called an instance of class or less confusing an object of class đ
+ 2
There both the same thing, you create an object like this.
//Declare a variable of type in this case s is the variable of type Phone.
Phone s;
//Assign it a value using the "new" keyword unlike primitives its value will be a refrence that knows were the object is.
Phone s = new Phone();
+ 1
Object is instance of class, no difference