Writing a function inside the main method - Java

前端 未结 7 2149
半阙折子戏
半阙折子戏 2020-12-06 11:36

Can you write a method inside the main method? For example I found this code:

public class TestMax {
    public static void main(String[] args) {
    int i =         


        
7条回答
  •  天命终不由人
    2020-12-06 12:31

    you cannot directly define methods inside other methods in Java ( main method too).

    You should write the method in the same class as main. 
    

    Note: You could declare a class with methods inside another method

提交回复
热议问题