教育路上
摘要:在main方法中通过创建OutEmployee类的实例对象并通过无参构造方法对属性赋值,然后通过实例对象调用方法。以下是我们为大家整理的,相信大家阅读完后肯定有了自己的选择吧。
2021-06-06 21:08刘永莘
public class OutEmployee { String employeeName;//声明变量 String employeeAddress; public OutEmployee()//构造函数,初始化雇员姓名和地址 { employeeName="Corol"; employeeAddress="97WenHuaroad."; } //没有返回值的方法,return语句可省略。 public void displayDetails() {//输出姓名和地址 System.out.println("Name of an employee is:"+employeeName); System.out.println("Address of an employee is:"+"employeeAddress"); return;//无返回值 } public static void main(String[] args) { OutEmployee employee1=new OutEmployee();//生成雇员 employee1.displayDetails();//打印雇员信息 } }
访客的评论 2024/04/19 15:58
文中描述的是准确的吗,如何报名!