Skip to content
Sign upLog in
← Back to Community

what is instance of objects in java

Profile icon
MatthewXia

pls help. im struggling. :(:(:(:(:(:(:(:(:(:(:(:(:(:(:(:(:(:(:(:(:(:(:(:(:(:(:(:(:(:(:(:(:(:(:(:(:(:(:(:(:(:(:(:(:(:(:(:(:(:(:(:(:(:(:(:(:(:(:(:(:(:(:(:(:(:(:(:(:(:(:(:(:(:(:(:(:(:(

Answered by CodeLongAndPros [earned 5 cycles]
View Answer
Voters
Profile icon
MatthewXia
Comments
hotnewtop
Profile icon
CodeLongAndPros

An instance is something you can use. If you are in your house, your Samsung is an instance of a Tele-Vision. Your iPhone 6S is an instance of a smart-phone. ‘instanceof’ tells you what the instance came from.

For example (this will not work)

INSTANCEOF Samsung yields TV INSTANCEOF iPhone yields phone
Profile icon
MatthewXia

@CodeLongAndPros
ty so much :)

Profile icon
CodeLongAndPros

@MatthewXia
Sure thing!

Profile icon
Coder100

instanceof is just to see if an object is created by a class:

class Something { private final int name; Something (int name) { this.name = name; } } class Something2 { private final int name; Something (int name) { this.name = name; } } Something something = new Something(2); Something2 something2 = new Something2(3); something instanceof Something; // true something2 instanceof Something; // false
Profile icon
Coder100

whats your question?

Profile icon
MatthewXia

@Coder100
my question is whats a class

Profile icon
MatthewXia

@Coder100
sry i suck at coding