Home > Back-end >  Create an instance of this class, in the main function of a class does not lead to the main function
Create an instance of this class, in the main function of a class does not lead to the main function

Time:03-04

Create an instance of this class, in the main function of a class does not lead to the main function of nested loop execution? As shown in the following


Public class Access {

Public Access () {//define a constructor
}

Public static void main (String [] args) {//define the primary methods
Access t1=new Access ();//create an object
}
}

the above code, when the program is running, the main function to run first, and then create the Access class instances of t1, the main function in the process of t1 instance generated again by t1 instance to run automatically, it doesn't become an infinite loop?

CodePudding user response:

New objects themselves do not run, the main method will only run one more time

CodePudding user response:

Function calls will not perform, not only the main at program startup called once, after your new Access did not call main () constructor, so is not infinite loop,
Unless, you in the constructor to
Public Access () {
The main (null).//a good contrast, here to call a function, it would perform, otherwise don't call won't execute
}

CodePudding user response:

refer to the second floor qybao response:
function not call is not followed, the main in the program start time is called only once, after your new Access did not call main () constructor, so is not infinite loop,
Unless, you in the constructor to
Public Access () {
The main (null).//a good contrast, here to call a function, it would perform, otherwise don't call won't execute
}


Thank you very much,

CodePudding user response:

reference 1st floor mtian2020 response:
new objects themselves do not run, the main method will only run a


Thank you very much,

CodePudding user response:

refer to the original poster eisldkw response:
create an instance of this class, in the main function of a class does not lead to the main function of nested loop execution? As shown in the following


Public class Access {

Public Access () {//define a constructor
}

Public static void main (String [] args) {//define the primary methods
Access t1=new Access ();//create an object
}
}

the above code, when the program is running, the main function to run first, and then create the Access class instances of t1, the main function in the process of t1 instance generated again by t1 instance to run automatically, it doesn't become an infinite loop?



The main method is the static method and won't be executed repeatedly, the static method

CodePudding user response:

Yes, the main can only do a.
  • Related