A class is simply a "set of fields and methods". (In terms of mathematics, "field" is close to a variable or constant, and "method" is close to a function.)
class Sample01{
//field
int a = 0;
int b;
//Method
int sum(int c, int d){
return c+d;
}
int add_a(int c){
return a+c;
}
}
You can see it in the sample above. Like the second method, fields in the same class can appear inside the method. Note that if the argument is int a here, the one entered as an argument will be distinguished from "a" and the field will be distinguished from "this.a".
A package is a class or set of packages. The relationship between classes and packages is similar to the relationship between files and folders. You can access fields and methods in classes in the same package using the access modifier (.).
class Sample02{
int a = Sample01.a;
int b = 2;
public void main(String[] args){
int c = Sample01.sum(a,b);
System.out.println("c = " + c);
}
}
Running the above code should give you "c = 3". So how do you access fields, etc. in a class in another package? In such a case, use "import".
import package name.name of the class;
If you declare, you will be able to access the fields and methods of that class using the same procedure as before.