0

Okay,so I know ==> private int num1 <== is an instance variable but will ==> private static int num2 <== be an instance variable as well or a class variable??(Assuming there are methods declared afterwards along with the main class) And what is the difference between static and non-static.

public class Apples {

private int num1;
private static int num2;

  public int a (int c ){

  }

  public static int b (int d){


  }
}
Luis B
  • 1
  • 5
  • static belongs to the class, non-static belongs to each object. – Bill F Dec 05 '17 at 23:21
  • Instance variables belong to the instance of the class which you can call an Object. Class variables are also known as static member variables and belong to the class and have only copy of it. So if you change the static variable value then the change will reflect at all the places where ever it is used in your application. Please refer to link to see the difference between [static/non-static](https://www.sitesbay.com/java/java-static-and-non-static-variable) – Neelesh Dec 06 '17 at 00:34

0 Answers0