Computer Science, asked by Anonymous, 1 year ago

Plzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz heeelllllllllllllppppppppppppp meeeeeeeeeeee!!!!!! anyone
Plz answer fast its urgent!!!

In JAVA , why are instance variables referred to as fields of an object?

Please explain in simple language only.
Please Dont spam .
# Content and quality both required#
98 points and best answer will be surely brainliest I promise!

Answers

Answered by Anonymous
45
Hlo mate :-

Answer :-

__________________________________________________________________________________

● Variables defined inside methods, constructors or blocks are called local variables.

●The variable will be declared and initialized within the method and it will be destroyed when the method has completed

● Instance variables are variables within a class but outside any method.

__________________________________________________________________________________

☆ ☆ ☆ Hop It's helpful ☆ ☆ ☆

vanshikabakshi: where do u live
Anonymous: Can U all plz stop it
vanshikabakshi: what the hell
vanshikabakshi: OK ok
vanshikabakshi: sry
vanshikabakshi: nhi
vanshikabakshi: kya bolo
Answered by siddhartharao77
8

Short note on Instance variables:

⇒ If the value of variable is varied from object to object such type of variables are instance variables.

(or)

A variable which is declared inside the class but outside the method.

⇒ An instance variable is one whose memory space is creating each and every time whenever an object is created and destroyed at the time of object destruction.

⇒ Instance variable must be accessed with respect to object name.

⇒ For every object a separate copy of instance variable is created.

⇒ They are stored on the heap as the part of an object.

⇒ They are also known as object level data members.

⇒ using object reference we can access instance variables from static area.

⇒ Field is generally a private variable on instance class. (or) It can store the state of an object. So, we can say that instance variable are fields.

⇒ An instance field, or field, is a variable that bound to the object itself.It is different for each instance of the object.

⇒ Their life span is until the object is available in the memory.


Example:

class Demo

{

int i = 5;

public static void main(String[] args)

{

Demo d = new Demo();

System.out.println(d.i);

d.display();

}

public void display()

{

System.out.println(i);

}

}

Note: For the instance variables it is not required to perform initialization JVM will always provide default values.

Output:

5

5



Hope it helps!


siddhartharao77: thanks!
Anonymous: awesome sid bhai ;)
Anonymous: superb ^_^
siddhartharao77: thanks sis
Similar questions