首页 > 其他 > 详细

有static的方法和没有static的调用

时间:2019-12-13 17:09:56      阅读:190      评论:0      收藏:0      [点我收藏+]

package com.yh.test02;

public class Test {

public static void main(String[] args) {
Test.method1();
method1();

Test t=new Test();
t.method2();
t.method1();
}
public static void doSome(){
System.out.println("doSome方法执行");
}
public void doOther(){
System.out.println("doOther方法执行");
}

public static void method1(){
System.out.println("=========");
Test.doSome();
doSome();
Test t1=new Test();
t1.doSome();
System.out.println("method1方法执行");
t1.doOther();
}
public void method2(){
System.out.println("2=========");
Test.doSome();
doSome();
Test t2=new Test();
t2.doOther();
t2.doSome();
System.out.println("method2方法执行");
}
}

 

 

 

 

方法名上有static关键字用类名.方法名();

          用方法名();

        还可以用引用.方法名();

方法名上没有static关键字用引用.方法名();

  引用指向了JVM的堆内存java对象

有static的方法和没有static的调用

原文:https://www.cnblogs.com/god1/p/12036115.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!