小编Dil*_*iya的帖子

在Java中,运算符优先级、递增和递减,为什么不执行第一个println语句?

class Example{
    public static void main(String args[]){
        int x=99;
        if(x++==x){
            System.out.println("x++==x : "+x); //Why this code line is not run?
        }
        if(++x==x ){
            System.out.println("++x==x : "+x); 
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

为什么第一条语句没有println执行?

java

-1
推荐指数
2
解决办法
91
查看次数

为什么匿名内部类的 Java 中 human.x=10 和 human.test(0) 编译错误?

class Human {

    void eat() {
        System.out.println("human eat!");
    }
}

public class Demo {

    public static void main(String[] args) {
        Human human = new Human() {
            int x = 10;

            public void test() {
                System.out.println("test - anonymous");
            }

            @Override
            void eat() {
                System.out.println("customer eat!");
            }

        };

        human.eat();
        human.x = 10;   //Illegal
        human.test();   //Illegal
    }
}
Run Code Online (Sandbox Code Playgroud)

这段代码为什么会human.x=10;出现human.test(0);编译错误?

java oop compiler-errors class anonymous-class

-1
推荐指数
1
解决办法
56
查看次数

标签 统计

java ×2

anonymous-class ×1

class ×1

compiler-errors ×1

oop ×1