• java14


    十四章
         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();
        }
    }
  • 相关阅读:
    【leetcode】字符串轮转
    【leetcode】URL化
    【leetcode】学生出勤记录 I
    【leetcode】子域名访问计数
    【leetcode】整数的各位积和之差
    【leetcode】另一个树的子树
    【leetcode】查询后的偶数和
    【leetcode】左叶子之和
    【leetcode】从根到叶的二进制数之和
    【leetcode】平方数之和
  • 原文地址:https://www.cnblogs.com/songziqiang-/p/6970216.html
Copyright © 2020-2023  润新知