非静态方法调用的问题

package com.web;

public class Test17 {
    
    
    public static void main(String[] args) {
    
    
        new Test17().method2();
        new Test17().method1();;
    }

    public void method2() {
    
    
        method1();
        //method2();//不可以这么调用自己,报错
    }

    private void method1() {
    
    
        boolean bool = 1 == 4 || 1 < 4;//boolean可以这么定义,不用加(1 == 4 || 1 < 4)
        System.out.println("bool = " + bool);
    }
}
/*
bool = true
bool = true
*/

猜你喜欢

转载自blog.csdn.net/djydjy3333/article/details/121375241