面向对象编程的初步演示

package com.lxk.jsu;

//定义了一个名为MyGirlFriend的类
class MyGirlFriend {

    //定义属性,成员变量
    private String name;
    private int age;
    private String sex;

    //有参构造方法
    public MyGirlFriend(String name, int age, String sex) {
        this.name = name;
        this.age = age;
        this.sex = sex;
    }

    //说话方法
    public void say() {
        System.out.println(this.name+" :爱意随风起,风止意难平,遗憾终究是遗憾。");
    }
}

主程序

package com.lxk.jsu;

//在主程序中使用MyGirlFriend类
public class RunDemo {
    public static void main(String[] args){
        //给自己一个野生的女朋友
        MyGirlFriend myGirlFriend = new MyGirlFriend("流莹", 18, "女");
        //让她说话
        myGirlFriend.say();
    }
}

输出:

E:\develop\Java\jdk-17\bin\java.exe "-javaagent:E:\idea\IntelliJ IDEA Community Edition 2023.3.4\lib\idea_rt.jar=55052:E:\idea\IntelliJ IDEA Community Edition 2023.3.4\bin" -Dfile.encoding=UTF-8 -classpath E:\code\stduy1\out\production\stduy1 com.lxk.jsu.RunDemo
流莹 :爱意随风起,风止意难平,遗憾终究是遗憾。

Process finished with exit code 0

作者本人也是初学,希望能和各位一同进步!

相关推荐

  1. 面向对象编程初步演示

    2024-03-23 02:06:02       40 阅读
  2. python面向对象编程

    2024-03-23 02:06:02       26 阅读
  3. Python中面向对象编程

    2024-03-23 02:06:02       57 阅读
  4. 面向对象编程类详解

    2024-03-23 02:06:02       27 阅读
  5. 面向对象编程6大原则

    2024-03-23 02:06:02       27 阅读
  6. Python面向对象编程

    2024-03-23 02:06:02       62 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-03-23 02:06:02       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-03-23 02:06:02       100 阅读
  3. 在Django里面运行非项目文件

    2024-03-23 02:06:02       82 阅读
  4. Python语言-面向对象

    2024-03-23 02:06:02       91 阅读

热门阅读

  1. C++ 字符串转数字的几种方法

    2024-03-23 02:06:02       44 阅读
  2. 如何在Docker容器启动时自动运行脚本

    2024-03-23 02:06:02       42 阅读
  3. linux常用命令

    2024-03-23 02:06:02       27 阅读
  4. 【 Vue 】自定义渲染器和异步渲染

    2024-03-23 02:06:02       35 阅读
  5. 进程的概念介绍

    2024-03-23 02:06:02       44 阅读
  6. 蓝桥杯 分糖果

    2024-03-23 02:06:02       38 阅读
  7. linux系统kubernetes的ServiceAccount和RBAC角色访问控制

    2024-03-23 02:06:02       42 阅读
  8. 企业应用开发中.NET EF常用哪种模式?

    2024-03-23 02:06:02       39 阅读