What is the result?

Given:

1. interface DeclareStuff {
2. public static final int EASY = 3;
3.
4. void doStuff(int t);
5. }
6.
7. public class TestDeclare implements DeclareStuff {
8. public static void main(String[] args) {
9. int x = 5;
10. new TestDeclare().doStuff(++x);
11. }
12.
13. void doStuff(int s) {
14. s += EASY + ++s;
15. System.out.println(“s ” + s);
16. }
17. }

What is the result?

Given:

1. interface DeclareStuff {
2. public static final int EASY = 3;
3.
4. void doStuff(int t);
5. }
6.
7. public class TestDeclare implements DeclareStuff {
8. public static void main(String[] args) {
9. int x = 5;
10. new TestDeclare().doStuff(++x);
11. }
12.
13. void doStuff(int s) {
14. s += EASY + ++s;
15. System.out.println(“s ” + s);
16. }
17. }

What is the result?

A.
s 14

B.
s 16

C.
s 10

D.
Compilation fails.

E.
An exception is thrown at runtime.

Explanation:
Main.java:13: doStuff(int) in TestDeclare cannot implement doStuff(int) in DeclareStuff; attempting to assign weaker access privileges; was public
void doStuff(int s) {
^
1 error



Leave a Reply 1

Your email address will not be published. Required fields are marked *