SCJP Practice questions – 1

Share this Article :


4) Compile and run with output of “Pausing” and “Continuing” after a key is hit
An overriden method in a sub class must not throw Exceptions not thrown in the base class. In the case of the method amethod it throws no exceptions and will thus compile without complain. There is no reason that a constructor cannot be protected.
________________________________________
Answer 32)
Objective 6.3)
4) Compile time error because of the line creating the instance of Inner

This looks like a question about inner classes but it is also a reference to the fact that the main method is static and thus you cannot directly access a non static method. The line causing the error could be fixed by changing it to say
Inner i = new Outer().new Inner();
Then the code would compile and run producing the output “Inner”
________________________________________
Answer 33)
Objective 4.6)
1) Error at compile time
If you implement an interface you must create bodies for all methods in that interface. This code will produce an error saying that MyWc must be declared abstract because it does not define all of the methods in WindowListener. Option 4 is nonsense as comments can appear anywhere. Option 3 suggesting that it might compile but not produce output is ment to mislead on the basis that what looks like a constructor is actually an ordinary method as it has a return type.
________________________________________
Answer 34)
Objective 1.2)
4) Compile time error
An error will be caused by attempting to define an integer as static within a method. The lifetime of a field within a method is the duration of the running of the method. A static field exists once only for the class. An approach like this does work with Visual Basic.
________________________________________
Answer 35)
Objective 9.5)
4)int z = 015;
The letters c and s do not exist as literal indicators and a String must be enclosed with double quotes, not single as in this case.
________________________________________
Answer 36)

Pages: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19

Written by bhaskar

{bhaskar has written 11 posts on ITTreats.com . See all posts by }


Leave a Reply