If constructors are implicitly invoked functions at the time of object creation then we should declare variable in constructor , but it is giving an error.
class A{
public A(){
int a =5;
}
}
public class assignment2 {
public static void main(String[] args) {
A obj = new A();
System.out.println(obj.a);
}
}
Error:
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
a cannot be resolved or is not a field
at ass2.main(ass2.java:14)