java:第十四章

十四章
     1.方法定义
        public 返回值类型 方法名(参数类型1 参数名1,参数类型2 参数名2···){
        //方法体
        }
     2.有参数的调用
        a.如果同一个类中,方法可以直接调用。
        b.如果是不同的类,方法必须通过对象调用,
          对象名,方法名(实参1,实参2···);
       注意:1.实参的数据类型,参数的个数,参数的顺序要与形参保持一致
             2.调用返回值的方法,一般要接收返回值,并作出相应的处理。


public class Excelle {
    private String type;
    private String id;
    public Excelle(){
        
    }
    
    public  Excelle(String type,String id ){
        this.type = type;
        this.id = id;
    }
    public String getType(){
        return type;
    }
    public String getId(){
        return id;
    }

}


public class Excelle {
    public     static void main(String[] args){
        Seller sl = new Seller();
        Excelle car = new Excelle("abc","1");
        sl.sell(car);
        Regal rl = new  Regal("bbb","2");
        sl.sell(rl);
        Excelle ec = new Excelle("ccc","3");
        sl.sell(ex,5);
    }
}


public class Student {
    String name;
    int age;
    String sex;
    String subject;
    public Student(){
        
    }
    
    public Student(String name,int age,String sex,String subject){
        this.name = name;
        this.age = age;
        this.sex = sex;
        this.subject = subject;
    }
    public String getName(){
        return name;
    }
    public int getAge(){
        return age;
    }
    public String getSex(){
        return sex;
    }
    public String getSubject(){
        return subject;
    }
    public void wj(){
        System.out.println("我是"+this.name+"年龄"+this.age+"性别"+this.sex+"专业"+this.subject);
    }
}



public class Student{
    public static void main(String[] args){
        Student s = new Student("xy",18,"nan","aaa");
        s.getAge();
        s.getName();
        s.getSex();
        s.getSubject();
        s.wj();
    }
}

 

转载于:https://www.cnblogs.com/yangchan250/p/6961057.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值