# Instance /Field Variables

{% embed url="<https://youtu.be/dxIxNbkzMHM>" %}

{% hint style="info" %}
We can access the  instance variables with    dot ( . )&#x20;
{% endhint %}

{% hint style="danger" %}
By default instance variables are set to "null" . But from Dart 2.9 with null safety  you can't  do this . It will show you an error&#x20;
{% endhint %}

```dart
void main() {
  
  
  
  var employee1 =   Employee();  // Creating employee1 object   
  
  var  employee2 =  Employee(); // Creating employee2  object 
  
  
  
  //Attribute <=> Instance Variable <=> Field Variable 
  
  
   // Setting the instance variable of employee1 object 
   
  employee1.id =1;
  employee1.name ="John Doe";
  employee1.position ="CTO";
  employee1.companyname ="B"; // Overwritting companyname "A"
  
  
  
  employee2.id =2;
  employee2.name ="Jane Doe";
  employee2.position ="CEO";
  
 // companyname for employee2 will be set to "A" , because we 
 // didn't set it, it take the default value from class 
  
  
  
  
}

class Employee{
  
  
  int id;
  
  String name;
  
  String position;  

  String companyname = "A" ;
  
  
  
}
```

> In [object-oriented programming](https://en.wikipedia.org/wiki/Object-oriented_programming) with [classes](https://en.wikipedia.org/wiki/Class_\(computer_science\)), an **instance variable** is a [variable](https://en.wikipedia.org/wiki/Variable_\(programming\)) defined in a class (i.e. a [member variable](https://en.wikipedia.org/wiki/Member_variable)), for which each instantiated [object](https://en.wikipedia.org/wiki/Object_\(computer_science\)) of the class has a separate copy, or instance. An instance variable is similar to a [class variable](https://en.wikipedia.org/wiki/Class_variable).[\[1\]](https://en.wikipedia.org/wiki/Instance_variable#cite_note-1) An instance variable is a variable which is **declared in a class but outside of constructors, methods, or blocks**. Instance variables are created when an object is instantiated, and **are accessible to all the constructors, methods, or blocks in the class**.
>
> Each instance variable lives in memory for the life of the object it is owned by.\
> &#x20;<img src="/files/-MDR9U2BtD1pOB-MZbdE" alt="" data-size="line"> ***Source: Wikipedia***

#### <img src="/files/-MDR9U2BtD1pOB-MZbdE" alt="" data-size="line"> We can visualise the above code like below -&#x20;

![](/files/-MDH0rPocRYT0QVdG503)

![](/files/-MDH2ZIJ4LWhzU-B54bs)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://eece.gitbook.io/mist-innovation-club-flutter-course-1/dart-fundamentals-1/untitled-1/instance-and-field-variables.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
