A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© jwx555 中级黑马   /  2014-7-10 22:22  /  3638 人查看  /  34 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

class  
{
        int i = 3 ;
        public static void main(String[] args)
        {
                int i = 0 ;
                i = this.i + 4
                this.i = this.i - 3;
                System.out.println(this.i) ;
                System.out.println(i);
        }
}

请问最后打出的结果会是多少呢??

34 个回复

倒序浏览
很明显编译就报错了吧,this不能用在静态方法中吧。
回复 使用道具 举报
我先问问你怎么做到在这里用this关键字的还输出结果的....
回复 使用道具 举报
这个能编译成功吗
回复 使用道具 举报
:lol楼主再见~~~和面试说拜拜吧
回复 使用道具 举报
this关键字不能用在static函数中。。学习了。。
回复 使用道具 举报
this。。。。。
回复 使用道具 举报
郭可 中级黑马 2014-7-11 08:15:43
8#
0 7 this.表示当前对象 相当于类名.成员变量
回复 使用道具 举报
逗你玩呢
回复 使用道具 举报
没有结果,编译失败,没有类名。
回复 使用道具 举报
这是坑啊,稍不注意就说0和7了
回复 使用道具 举报
on-on 中级黑马 2014-7-11 09:24:11
12#
对于变量的测试不能放在主函数中,因为主函数是static类型,不能调用非static类型的变量,所以要单写一个类进行测试就对了
public class IntegerTest {
        public static void main(String []args){
                Test t = new Test();
                  t.test();
        }
          
}
class Test{
        int i = 3;
        public void test(){
                 int i = 0 ;
         i = this.i + 4;
         this.i = this.i - 3;
         System.out.println(this.i) ;
         System.out.println(i);
        }
}
回复 使用道具 举报 0 1
this关键字不能用在static函数,不能用在静态方法中!!!
回复 使用道具 举报
有深度!
回复 使用道具 举报
路过  学习了
回复 使用道具 举报
Beka 中级黑马 2014-7-11 12:15:31
16#
this不能用在静态方法中啊,学习了
回复 使用道具 举报
我也被坑了   看见第一反应居然是 0  7
回复 使用道具 举报
学习了{:3_47:}
回复 使用道具 举报
学习一下。。
回复 使用道具 举报
崔MQ 中级黑马 2014-7-11 12:36:58
20#
坑货一个啊 !
回复 使用道具 举报
12下一页
您需要登录后才可以回帖 登录 | 加入黑马