(moved from below - to better suit my reply.)
>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.
The protected members are accessible, though not
quite in the way you are trying..
See my changes to your second class.
>I have the following piece of code -
>
>*******************************************************************************************
>1. package MyPack;
>2.
>3. public class Balance {
...
>20. } /*class Balance*/
>21.
>22. // Subclass of Balance in a different package
package testing;
import MyPack.Balance;
public class TestBalance extends Balance{
TestBalance(String name, double balance) {
super(name, balance);
}
public static void main(String args[]) {
TestBalance mybalance = new TestBalance("Someone",1000);
mybalance.Show();
}
} /*class TestBalance*/
The code as above should compile cleanly. I am
going to avoid trying to explain further, I'll leave that
to the JLS/OO gurus.

Signature
Andrew Thompson
http://www.athompson.info/andrew/
Lew - 21 Sep 2007 14:29 GMT
sayantan.chowdhury@gmail.com wrote:
>> 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.
For use for their own construction only, not to create "third-party" objects.
> The protected members are accessible, though not
> quite in the way you are trying..
>> 22. // Subclass of Balance in a different package
> package testing;
>
> import MyPack.Balance;
BTW, OP, packages should be named with all lower-case letters, by convention.
> public class TestBalance extends Balance{
>
[quoted text clipped - 13 lines]
> going to avoid trying to explain further, I'll leave that
> to the JLS/OO gurus.
<http://java.sun.com/docs/books/jls/third_edition/html/names.html#6.6.2.2>
You can use a constructor for the object itself, inheriting the constructor,
but not for another object, where inheritance isn't involved.

Signature
Lew
Andrew Thompson - 21 Sep 2007 14:40 GMT
...
(Andrew T.)
>> ..going to avoid trying to explain further, I'll leave that
>> to the JLS/OO gurus.
[quoted text clipped - 3 lines]
>You can use a constructor for the object itself, inheriting the constructor,
>but not for another object, where inheritance isn't involved.
(Checks watch) 10 minutes (swears loudly).
Does that mean I don't "get my pizza for free"? ;-)

Signature
Andrew Thompson
http://www.athompson.info/andrew/
Lew - 21 Sep 2007 14:44 GMT
>>> ..going to avoid trying to explain further, I'll leave that
>>> to the JLS/OO gurus.
Lew wrote:
>> <http://java.sun.com/docs/books/jls/third_edition/html/names.html#6.6.2.2>
>>
>> You can use a constructor for the object itself, inheriting the constructor,
>> but not for another object, where inheritance isn't involved.
AT:
> (Checks watch) 10 minutes (swears loudly).
> Does that mean I don't "get my pizza for free"? ;-)
I hadn't actually known that rule until this question. I intuited it and
smiled when I saw your answer, because it meant I was right, but I didn't know
it until I looked it up.
Whenever faced with a subtle or bizarre Java behavior, I hit the JLS. It's
almost always settled the matter within seconds.

Signature
Lew
Andrew Thompson - 21 Sep 2007 14:34 GMT
But a couple of small points I forgot to mention.
Using the common nomenclature for classes, methods
and attributes helps others to understand the code.
These common 'rules'* would mean that MyPack
should be all lower case, hence mypack, but even
then, abbreviations within the lower case form can
become very confusing, so 'mypackage' would be
better.
Now that I say that, I realise that the majority (not all)
of package names in the J2SE are one word.
On the same topic, methods and non-final attributes
should be what is known as camelCase, with first
letter lower case, and each other word starting with
an Upper Case letter. So, e.g. Show() should be show().

Signature
Andrew Thompson
http://www.athompson.info/andrew/
On Fri, 21 Sep 2007 05:34:47 -0700, "sayantan.chowdhury@gmail.com"
<sayantan.chowdhury@gmail.com> wrote, quoted or indirectly quoted
someone who said :
>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.
If you wan that extreme visibility, you must use public. Protected is
a bit weaker than that. See http://mindprod.com/jgloss/protected.html
http://mindprod.com/jgloss/scope.html

Signature
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com
sayantan - 24 Sep 2007 05:47 GMT
Hi Roedy,
I went through the link you provided.It's written that the "protected"
is visible to classes outside the package that inherit the class.
And this is my exact point of confusion as I should not get these
errors accroding to this rule.
Thanks,
Sayantan
> >Could someone please explain to me the reasoning behind these errors.
> >As I understand, protected members are accesible to the subclasses in
[quoted text clipped - 5 lines]
> Roedy Green Canadian Mind Products
> The Java Glossaryhttp://mindprod.com
Lew - 24 Sep 2007 06:20 GMT
> Hi Roedy,
>
> I went through the link you provided.It's written that the "protected"
> is visible to classes outside the package that inherit the class.
> And this is my exact point of confusion as I should not get these
> errors accroding to this rule.
Please do not top-post.
This was answered earlier. Read:
<http://java.sun.com/docs/books/jls/third_edition/html/names.html#6.6.2.2>
As I mentioned:
> You can use a constructor for the object itself, inheriting the constructor,
> but not for another object, where inheritance isn't involved.
In other words, the protected constructor can only be used by the object
itself, i.e., through an implicit or explicit super() call (or other
constructor). You were calling the constructor of an object other than this.
That is forbidden.
It is not enough that the invoking object be of the child class. It must also
be constructing itself.
Did you have difficulty with this answer before? What is the part that gives
you trouble?

Signature
Lew
Roedy Green - 25 Sep 2007 03:58 GMT
On Mon, 24 Sep 2007 04:47:00 -0000, sayantan
<sayantan.chowdhury@gmail.com> wrote, quoted or indirectly quoted
someone who said :
>I went through the link you provided.It's written that the "protected"
>is visible to classes outside the package that inherit the class.
>And this is my exact point of confusion as I should not get these
>errors accroding to this rule.
Oops, I gave you the wrong URL. Try this improved one.
http://mindprod.com/jgloss/protectedscope.html

Signature
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com