public class Employee
{
String name;
int age;
String designation;
double salary;
public Employee(String name)
{
this.name = name;
}
public void empAge(int empAge)
{
age = empAge;
}
public void empDesignation(String empDesig)
{
designation = empDesig;
}
public void empSalary(double empSalary)
{
salary = empSalary;
}
public void printEmployee()
{
System.out.println("名字:"+ name );
System.out.println("年龄:" + age );
System.out.println("职位:" + designation );
System.out.println("薪水:" + salary);
}
/* ======================================================*/
public static void main(String args[]) //入口函数,主类
{
Employee empOne = new Employee("RUNOOB1");
Employee empTwo = new Employee("RUNOOB2");
empOne.empAge(26);
empOne.empDesignation("高级程序员");
empOne.empSalary(1000);
empOne.printEmployee();
empTwo.empAge(21);
empTwo.empDesignation("菜鸟程序员");
empTwo.empSalary(500);
empTwo.printEmployee();
}
}
说明:如果如上把主类放在Employee类中,则javac出错:(但如果把主类写在另一个EmployeeTest类中则javac EmployeeTest.java 可以通过,java EmployeeTest 也可以成功,但无法理解,特来请教园中大神们 )
javac命令 要带.java后缀
java命令 不要带.java后缀
你那是使用命令提示符的方法错误,编译错了,你看下下面的写法
javac (文件名).java
java (文件名)