S
sayantan.chowdhury
Hi all,
I have the following piece of code -
*******************************************************************************************
1. package MyPack;
2.
3. public class Balance {
4. private String name;
5. private double bal;
6.
7. protected Balance() {
8.
9. }
10.
11. protected Balance (String A,double B) {
12. name = A;
13. bal = B;
14. }
15.
16. protected void Show () {
17.
18. System.out.println(name +" : $"+bal);
19. }
20. } /*class Balance*/
21.
22. // Subclass of Balance in a different package
23.
24. package testing;
25.
26. import MyPack.Balance;
27.
28. public class TestBalance extends Balance{
29.
30. public static void main(String args[]) {
31.
32. Balance mybalance = new Balance("Someone",1000);
33. mybalance.Show();
34.
35. }
36. } /*class TestBalance*/
*******************************************************************************************************
While compiling the above code, I'm getting the following error in
line #32 -
"The constructor Balance(String,double) is not visible"
and the following error in line #33 -
"The method Show() from the type Balance is not visible"
Could someone please explain to me the reasoning behind these errors.
As I understand, protected members are accesible to the subclasses in
a different package.
Any pointers to any reading material will be appreciated.
Thanks,
Sayantan Chowdhury
I have the following piece of code -
*******************************************************************************************
1. package MyPack;
2.
3. public class Balance {
4. private String name;
5. private double bal;
6.
7. protected Balance() {
8.
9. }
10.
11. protected Balance (String A,double B) {
12. name = A;
13. bal = B;
14. }
15.
16. protected void Show () {
17.
18. System.out.println(name +" : $"+bal);
19. }
20. } /*class Balance*/
21.
22. // Subclass of Balance in a different package
23.
24. package testing;
25.
26. import MyPack.Balance;
27.
28. public class TestBalance extends Balance{
29.
30. public static void main(String args[]) {
31.
32. Balance mybalance = new Balance("Someone",1000);
33. mybalance.Show();
34.
35. }
36. } /*class TestBalance*/
*******************************************************************************************************
While compiling the above code, I'm getting the following error in
line #32 -
"The constructor Balance(String,double) is not visible"
and the following error in line #33 -
"The method Show() from the type Balance is not visible"
Could someone please explain to me the reasoning behind these errors.
As I understand, protected members are accesible to the subclasses in
a different package.
Any pointers to any reading material will be appreciated.
Thanks,
Sayantan Chowdhury