6 10 pts What is wrong with the following code How should it

6. (10 pts) What is wrong with the following code? How should it be fixed?

1 public class H2ClassG {
2   final int x;
3
4   H2ClassG () {}
5   H2ClassG (int a) {x = a;}
6 } // end class H2ClassG

Solution

Solution:

X is final so we need to initialize and we can change it. So, We can fix both errors by doing:
publicclass H2ClassG {
privateintx;

H2ClassG () {}
H2ClassG (int a) {x = a;}
} // end class H2ClassG

6. (10 pts) What is wrong with the following code? How should it be fixed? 1 public class H2ClassG { 2 final int x; 3 4 H2ClassG () {} 5 H2ClassG (int a) {x = a

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site