当前位置:网站首页>类与对象
类与对象
2022-07-17 05:22:00 【INSIGNER】
类class
- 类是对象的抽象,描述了对象的基本类型。如每个人有年龄、名字,会吃饭、睡觉、打游戏。类就是将这些,人的共同特征用抽象的放法表现出类。
- 类也是,面向对象编程语言,实现面向对象的基本单位。一个完整的Java程序至少包含一个类。
类的定义
定义一个:
//定义一个表示人的类
public class Person{
int age; //人有年龄
String name; //人有名字
public void sleep(){
//睡觉的方法
System.out.print("睡觉");
}
public void eat(){
//吃饭的方法
System.out.println("吃饭");
}
public void playGame(){
//打游戏的方法
System.out.println("打游戏");
}
}
- 在同一个源文件中可以包含多个类,但只有一个类可以使用public来修饰。
对象
对象可以说是,类的实体化表现。如果说类是一张蓝图,对象就是类的具体实现。人的蓝图构建的对象就是有名字、有年龄的不同的人。
定义一个对象:
public class Persons{
public static void main(String[] args) {
Person person = new Person();
person.name = "张三";
person.eat();
}
}public class Persons{
Person zhangsan = new Person();
zhangsan.name = "张三";
}
边栏推荐
- [automated testing] - robotframework practice (II) new test cases
- Xiaodi - network security notes (1)
- 阿里云、腾讯云、华为云、Ucloud(优刻得)、天翼云 的云服务器性能测试和价格对比
- F5 GTM (I): DNS parameters
- 高并发day04(ZAB协议,观察者,nc,AVRO,RPC)
- Relevant knowledge points of Gugao motion control card
- About file upload and download
- Huawei routing port mapping
- Galaxy Kirin server system building local and LAN Yum source
- Xiaodi network security notes - Information Collection - architecture, construction, WAF (8)
猜你喜欢

Review summary of MySQL

Comparison between CS brand SD NAND and SPI NAND

Programming learning based on ardunio ide software development

传奇游戏架设教程

OLED data display based on spi/iic interface

Alibaba cloud Hangzhou arm ECS performance evaluation

Minecraft Paper 1.18.1 版开服教程,我的世界开服教程,MCSManager9面板使用教程

Minecraft bedrock BDS service tutorial

Tcp/ip four layer model and related configurations of F5
![[automated testing] - robotframework practice (II) new test cases](/img/e8/b5e945400445c66e3a7a129744c21d.png)
[automated testing] - robotframework practice (II) new test cases
随机推荐
Redraiment的遭遇
[automated testing] - robotframework practice (III) writing test cases
notepad++下划线以及大小写字母置换
SSH remote login service
网站被劫持了怎么办?
day01(Flume)
文本三剑客之awk命令--截取
企业或个人域名备案怎么弄
文本三劍客之awk命令--截取
UCloud(优刻得) 上海 ARM 云服务器评测
解决sonar的单元测试的覆盖率会为0问题
汉诺塔2(函数)
ANAME
轻重搭配(贪心)
tail -f暂停方法
FreeBSD 12 国内源提速 pkg 和 ports 做个笔记
Programming learning based on ardunio ide software development
各大云服务厂商 轻量应用服务器 性能评测对比,阿里云、腾讯云、华为云、Ucloud
Xiaodi network security - Notes (2)
Top command