首页 > 其他 > 详细

this/static

时间:2020-10-08 20:11:02      阅读:57      评论:0      收藏:0      [点我收藏+]
public class text{
 // 没有statc的变量i
 int i=19;
 // 带有static的变量abstract
 static int a=10;
 // 带有static的方法doSome
 public static void doSome(){
  System.out.println("do some!");
 }
 public void doOther(){
  System.out.println("do other!");
 }
 public void method1(){
  // 调用doSome
  // 完全方式调用
  text.doSome();
  // 省略方式调用
  doSome();
  // 调用doOther
  // 完全方式调用
  this.doOther();
  // 省略方式调用
  doOther();
  // 访问i
  // 完全方式访问
  System.out.println(this.i);
  // 省略方式访问
  System.out.println(i);
  // 访问a
  // 完全方式访问
  System.out.println(text.a);
  // 省略方式访问
  System.out.println(a);
 }
 public static void method2(){
     // 调用doSome
  // 完全方式调用
  text.doSome();
  // 省略方式调用
  doSome();
  // 调用doOther
  // 完全方式调用
  text t=new text();
  t.doOther();
  // 省略方式调用
  // 访问i
  // 完全方式访问
  // 省略方式访问
  System.out.println(t.i);
  // 访问a
  // 完全方式访问
  System.out.println(text.a);
  // 省略方式访问
  System.out.println(a);
 }
 public static void main (String[] args){
  // 调用method1
  // 完全方式调用
  text v=new text();
  v.method1();
  // 省略方式调用
  // 调用method2
  // 完全方式调用
  text.method2();
  // 省略方式调用
  method2();
 }
}

this/static

原文:https://www.cnblogs.com/wangmoumou/p/13782354.html

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