11月14日报告

1.面向对象 

package com.langsin.Method.student;

public class Student {
    String name;
    String gender;
    int age;
    String school;
    String major;

    //构造方法
    //构造方法名称与类名保持一致
    public Student(){
        System.out.println("类默认提供了一个无参的构造方法方便我们创建该类的对象");
    }

    public void study(int hour) {
        System.out.println("这位仁兄学习了" + hour + "小时");
    }

    public void eat(String food) {
        System.out.println("这位仁兄吃了" + food);
    }

    public void play(String game) {
        System.out.println("这位仁兄开心地玩了" + game);
    }


}

package com.langsin.Method.student;

public class Demo {
    public static void main(String[] args) {
       //已经存在了学生类
       // 现在要表示一个具体的学生对象
      //Scanner scanner=new Scanner(System.in);
      //new Student()   调用了一个无参的构造方法,创建了一个学生对象
      Student student1 =new Student();
      //属性在堆中存放
      student1.name="陈铮";
      student1.age=12;
      student1.gender="男";
      student1.school="齐鲁工业大学";
      student1.major="人工智能";

      System.out.println(student1.name);
      System.out.println(student1.age);
      System.out.println(student1.gender);
      System.out.println(student1.school);
      System.out.println(student1.major);
      student1.eat("红豆饼");
      student1.play("堡垒之夜");
      student1.study(6);

      Student student2=new Student();
      student2.name="刘宇轩";
      student2.age=15;
      student2.gender="女";
      student2.school="齐鲁工业大学";
      student2.major="车辆工程";

      Student student3=new Student();
      student3.name="肖雨涵";
      student1.age=14;
      student1.gender="女";
      student1.school="齐鲁工业大学";
      student1.major="地下工程";

    }
}

2.类成员的定义

(1)构造方法的定义

[修饰符] 构造器名(形参列表){}

修饰符:public protected private

构造器名:与类名保持一致

不要写返回值类型(void int double.....)

package com.langsin.Method.computer;

import java.util.Arrays;

public class Computer {
    String brand;
    double price;
    String color;

    //JAVA会默认提供一个无参的构造方法
//    public Computer() {
//    }

    //构造方法的作用:通过new关键字来调用,完成对象的初始化(创建)操作
    //如何区分重名的局部变量和成员变量
    //通过this关键字取到成员变量和成员方法
    //this指的是正在执行此方法的对象
    public Computer(String brand, double price, String color) {
    this.brand=brand;
    this.color=color;
    this.price=price;
    }

    //方法的重载
    //在JAVA中可以定义名称相同但参数列表不同的方法
    //    public void play(){
    //
    //    }
    int[] a = new int[5];
    String string = Arrays.toString(a);


    public void play(String game) {

    }

    public void study(int hour) {

    }
}

 

package com.langsin.Method.computer;

public class ComputerDemo {
    public static void main(String[] args) {
       Computer computer1=new Computer("戴尔",8888.0,"绿色");
        System.out.println(computer1.brand);
        System.out.println(computer1.color);
        System.out.println(computer1.price);
        Computer computer2=new Computer("苹果",7777.0,"蓝色");
        System.out.println(computer2.brand);
        System.out.println(computer2.color);
        System.out.println(computer2.price);

    }
}

           

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

蒂法挤挤挤

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值