Import syntax is a way to find the appropriate location for a particular class for the compiler.
Create an employee class that includes four entity variable names (name), age, Position (designation), and salary (salary).
1 Public classEmployee {2 String name;3 intAge ;4 String designation;5 Doublesalary;6 7 //Constructors8 PublicEmployee (String name) {9 This. Name =name;Ten } One A //Assigning a value to an entity variable - Public voidEmpage (intempage) { -Age =Empage; the } - - Public voidempdesignation (String empdesig) { -designation =Empdesig; + } - + Public voidEmpsalary (intempsalary) { ASalary =empsalary; at } - - //ways to print job seekers ' information - Public voidPrintemployee () { -System.out.println ("Name:" +name); -System.out.println ("Age:" +Age ); inSYSTEM.OUT.PRINTLN ("designation:" +designation); -System.out.println ("Salary:" +salary); to } +}
It then creates a employeetest class that creates instances of two Employee classes, and invokes methods for each object to assign values to each variable.
This imports the employee class that you just created, which is created under the AAA folder, gives the fully qualified name of the name that includes the encapsulation and the class, and the compiler can easily navigate to the source class and source code.
1 ImportAAA. Employee;2 3 Public classEmployeetest {4 Public Static voidMain (String args[]) {5Employee Empone =NewEmployee ("Jacky");6Employee Emptwo =NewEmployee ("Tom");7 8Empone.empage (26);9Empone.empdesignation ("Engineer");TenEmpone.empsalary (2000); One Empone.printemployee (); A -Emptwo.empage (20); -Emptwo.empdesignation ("Teacher"); theEmptwo.empsalary (1000); - Emptwo.printemployee (); - } -}
Run output:
name:jackyage:designation:engineersalary:2000.0name:tomage:designation: Teachersalary:1000.0
If Employee.java is in a sibling folder, import this step can be ignored.
Java Learning Note (iv): import syntax