Discussion
What will be the output of the program?
import java.util.*;
public class NewTreeSet2 extends NewTreeSet
{
public static void main(String [] args)
{
NewTreeSet2 t = new NewTreeSet2();
t.count();
}
}
protected class NewTreeSet
{
void count()
{
for (int x = 0; x < 7; x++,x++) /* Line 14 */
{
System.out.print(" " + x);
}
}
}
Answer: D
Correct answer: Compilation fails at line 10
A top-level class may be declared public or left package-private, and nothing else: protected and private are meaningful only for members of a class, since they are defined by reference to a containing type. Line 10 declares protected class NewTreeSet at the top level, which the compiler rejects. The loop itself would have printed 0 2 4 6, since x++,x++ advances by two each pass.
No comment is present. Be the first to comment.
Loading…
Post your comment
Please log in or register to post a comment.
Examination Categories
- SSC Exams
- Banking Exams
- Teaching Exams
- Civil Services Exams
- Railways Exams
- Engineering Recruitment Exams
- Defence Exams
- State Government Exams
- Police Exams
- Insurance Exams
- Nursing Exams
- Other Government Exams
- NRA CET
- PG Entrance Exams
- Campus Placement
- MBA Entrance Exams
- CUET and UG Entrance
- Judiciary Exams
- Regulatory Body Exams
- Software Development