当前位置:网站首页>【静态方法与非静态方法】
【静态方法与非静态方法】
2022-04-22 06:20:00 【Vi---Rum】
- 静态方法可以通过类名点方法名的方式调用
- 但是不能通过类名点方法名的方式调用非静态方法
- 可以通过类的实例化对象名点方法名的方式调用静态方法
- 也可以通过类的实例化对象名点方法名的方式调用非静态方法
- 静态方法可以调用静态方法但是无法直接调用非静态方法
- 非静态方法可以调用非静态方法与可以调用静态方法
public class Person {
public static void main(String[] args) {
sleap();
}
// 昵称
String nickname;
// 性别 1代表男 0代表女
int gender;
// 年龄
int age;
public void eat(){
System.out.println("少吃点");
drink();
}
public void drink(){
System.out.println("感情深,一口闷");
}
public static void sleep(){
System.out.println("韬光养晦");
}
}
public class Person01Test {
@Test
public void test01(){
// 静态方法可以通过类名点方法名的方式调用
// 但是不能通过类名点方法名的方式调用非静态方法
Person.sleep();
}
@Test
public void test02(){
// 静态方法可以通过类名点方法名的方式调用
// 但是不能通过类名点方法名的方式调用非静态方法
Person.sleep();
Person person01 = new Person();
// 可以通过类的实例化对象名点方法名的方式调用静态方法
// 也可以通过类的实例化对象名点方法名的方式调用非静态方法
person01.eat();
person01.drink();
person01.sleep();
}
}
版权声明
本文为[Vi---Rum]所创,转载请带上原文链接,感谢
https://blog.csdn.net/weixin_54371657/article/details/124306251
边栏推荐
- 最小圆覆盖(计算几何基础)
- 案例案例案例
- Use of ansible
- JS基础语法
- 1. Jam packed (Game 5 of 2021 training League warm-up training competition)
- 2019.1.2版的Idea使用教程
- APC(四)
- Kotlin learning 1. Scope functions let, with, run, apply, also
- 强网杯 2019 随便注
- L2-001 emergency rescue (extension of shortest Dijkstra - number of shortest paths & maximum weight of paths)
猜你喜欢

最小圆覆盖(计算几何基础)

Redis的设计与实现(1):了解数据结构与对象

VAD 虚拟内存

Bidirectional circular linked list (see details)

The system log file is too large

Addition, deletion and search of sequence table (find)

调用门

Ansible的使用

Minimum circle coverage (basis of computational geometry)

Queue (detailed explanation) -- hand tearing queue exercises
随机推荐
2019.1.2版的Idea使用教程
调用门
Educational Codeforces Round 122 (Rated for Div. 2)
深入理解MySQL(6):MySQL日志简析
Codeforces Round #634 (Div. 3)
E. Figure skiing (string sorting / check-in) (Game 5 of 2021 training League warm-up training competition)
Ffmpeg command (VIII). Add watermark to video
A. Binary seating (the fifth game of 2021 training League warm-up training competition)
1232. Minimum number of arrows for exploding balloons
Kotlin协程+Flow+Retrofit实现网络请求
A. Weird Flecks, But OK (计算几何&三维最小圆覆盖)(2021年度训练联盟热身训练赛第一场)
Blog synchronization update notification
Longest ascending sequence
Bom 浏览器对象模型
深入理解MySQL(7):MySQL如何调优
1. Jam packed (Game 5 of 2021 training League warm-up training competition)
HDU Ice_cream‘s world I (并查集判环)
Ffmpeg command (VII), combining audio and video into video
Recursive search sequence set
Detailed overview of this keyword