About Question enthuware.ocajp.i.v7.2.828 :
Moderator: admin
-
- Posts: 27
- Joined: Thu Feb 07, 2013 9:46 pm
- Contact:
About Question enthuware.ocajp.i.v7.2.828 :
Since the class is public class TestClass, don't we need a public static void main(String[] args). If yes then public int main(String[] args) in same class will give duplicate method error.
-
- Site Admin
- Posts: 10062
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.828 :
There doesn't have to be a public static void main(String[] args) in every class. i.e. it is not an error if you don't have this method in a class.
If you like our products and services, please help us by posting your review here.
-
- Posts: 9
- Joined: Fri Jun 26, 2015 11:15 am
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.828 :
I think, we can write both standard main() and other version main() in one class, but only be overloaded. If just overloaded main(), no error. Right?
Thanks.
Thanks.
-
- Site Admin
- Posts: 10062
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.828 :
Yes, right. But you sshould try it out.
If you like our products and services, please help us by posting your review here.
-
- Posts: 5
- Joined: Fri Sep 11, 2015 8:06 am
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.828 :
How are we supposed to know that the main method listed was not the intended standard main method but done wrong? I thought it was intended to be the public static void main(String[] args) method, but they just wrote it wrong to see if i'd catch it.
-
- Site Admin
- Posts: 10062
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.828 :
Unless mentioned otherwise, in this exam, wrong or invalid implies compilation error. In this question (problem statement and options), there is no mention of execution from command line, so you don't really know of the intention. Therefore, all you can see is whether the code will compile or not.
If you like our products and services, please help us by posting your review here.
-
- Posts: 1
- Joined: Wed Aug 19, 2020 11:12 am
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.828 :
Maybe I should not post this with this question, but this question leaves me confused.
The options to be answered: Which of the lines are invalid?
In this one "public int main(String[] args)" is not to be answered, because: " is a valid declaration of a method named main. Although, it is not a correct declaration for the standard main method that can be used to execute the class, but it is a valid method nevertheless."
I refer to the following other question and answer (enthuware.ocajp.i.v8.2.1080):
question: Which of the following are valid declarations for the standard main method:
wrong option: static void main(String args[])
answer: Although practically correct but for the purpose of this exam you should not select this option because the method is not declared public
and another wrong answer in that same question: public static int main(String args[ ]) {}
This method returns an 'int' instead of 'void'.
My confusion is in the fact that in one question a strict answer is expected but not in the other, can you give me some guidance in how to understand what is expected?
The options to be answered: Which of the lines are invalid?
In this one "public int main(String[] args)" is not to be answered, because: " is a valid declaration of a method named main. Although, it is not a correct declaration for the standard main method that can be used to execute the class, but it is a valid method nevertheless."
I refer to the following other question and answer (enthuware.ocajp.i.v8.2.1080):
question: Which of the following are valid declarations for the standard main method:
wrong option: static void main(String args[])
answer: Although practically correct but for the purpose of this exam you should not select this option because the method is not declared public
and another wrong answer in that same question: public static int main(String args[ ]) {}
This method returns an 'int' instead of 'void'.
My confusion is in the fact that in one question a strict answer is expected but not in the other, can you give me some guidance in how to understand what is expected?
-
- Site Admin
- Posts: 10062
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.828 :
The distinction is clear:
if the question is asking about the main method that is used to execute the class, pick the one with public static void main(String args[]) or other equivalent variation.
if the question is asking about the main method that is used to execute the class, pick the one with public static void main(String args[]) or other equivalent variation.
If you like our products and services, please help us by posting your review here.
Who is online
Users browsing this forum: No registered users and 71 guests