Using the Simple Name of an Instance Variable in an Instance Method - Java Object Oriented Design

Java examples for Object Oriented Design:Field

Description

Using the Simple Name of an Instance Variable in an Instance Method

Demo Code

public class Main {
  int num = 2017; // An instance variable

  void printNum() {
    System.out.println("Instance variable num: " + num);
  }/* w  w  w  .  j  av a  2 s. c  om*/

  public static void main(String[] args) {
    Main a = new Main();
    a.printNum();
  }
}

Result


Related Tutorials