//Edited:I guess I represented the question wrong. I am familiar the concept that "we need an instance to access non static variables and methods".
But my question was
When I type the prgm in my eclipse it shows an error at line B but I am expecting to show even on A//
This is a basic question please don't mind.
package com.sigma.java;
import java.util.*;
public class Test1 {
private int a=1;
public void add(){
System.out.println(a);-------->A
}
public static void main(String[] args) {
Test1 t=new Test1();
System.out.println(a);-------------->B
}
}
Compiler shows error in main method when trying print a(marked as B) (Error-Cannot make a static reference to the non-static field a) Question-Why dont I get the same error in add() method(marked as A)