Correct answer is A. class B won't compile as we can't have private or protected variables in a block. class C won't compile as package declaration should be first statement followed by import statement (s).
Only A.java wile compile.
Class B won't compile because the scope of the local variables belong to the method/block/constructor/ these are not accessed from outside, therefore, having access specifiers like public, private, protected (which allows access outside of the current context) makes no sense.
Class C won't compile as package should be the first statement and then import.
Not true. You can have a method called main, which is not static, but cannot be compiled through the command line directly. The issue here is the package statement following the import statement, when it should be the other way round.
A - correct, Only the A.Java file compiles successfully.
upvoted 5 times
...
Log in to ExamTopics
Sign in:
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.
Upvoting a comment with a selected answer will also increase the vote count towards that answer by one.
So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.
ashwinbalu
Highly Voted 4 years, 7 months agoStewart125
Highly Voted 4 years, 3 months agoMPignaProTech
Most Recent 3 months agoDriftKing
1 year, 4 months agodsms
1 year, 5 months agoVicky_65
1 year, 9 months agogfdhsfgcdfs
2 years, 5 months agorameasy
4 years, 5 months agozelimir
4 years, 10 months agokrkpnr
4 years, 10 months agoSaftschnitzel
4 years, 9 months agonatiqbashir
3 years, 11 months agov323rs
5 years ago