Why declaring a private abstract method makes no sense??

N

Neroku

Hello, I don't understand why a private abstract method declaration is
senseless, I do undersand why both declarations "final abstract" and
"static abstract" are senseless, but not so with "private abstract".

TIA
 
R

Robert Klemme

Hello, I don't understand why a private abstract method declaration is
senseless, I do undersand why both declarations "final abstract" and
"static abstract" are senseless, but not so with "private abstract".

private methods cannot be overridden in subclasses.

robert
 
A

Adam Maass

Neroku said:
Hello, I don't understand why a private abstract method declaration is
senseless, I do undersand why both declarations "final abstract" and
"static abstract" are senseless, but not so with "private abstract".

A private member is visible only to the class that declares it.Specifically,
a private member is not visible to subclasses. An abstract method is a
method where a subclass is expected to provide the implementation. But a
subclass couldn't see the declaration of the signature if the signature were
private.

-- Adam Maass
 
M

Mark Thornton

Adam said:
A private member is visible only to the class that declares it.

It is also visible to nested/inner classes of the declaring class.

Mark Thornton
 
D

Daniel Pitts

Hello, I don't understand why a private abstract method declaration is
senseless, I do undersand why both declarations "final abstract" and
"static abstract" are senseless, but not so with "private abstract".

TIA


a private method has the same properties as a final method, in that it
can never be overridden.

The super class can not see a private member of a derived class, and a
derived class cannot change the behaviour of any private methods in
the super class.
 
R

Robert Klemme

a private method has the same properties as a final method, in that it
can never be overridden.

That's not exactly true - they do not have the same properties: you
cannot have methods with the same signature in subclasses the "final"
case. But you can with private - only those versions won't override the
superclass method.
The super class can not see a private member of a derived class, and a
derived class cannot change the behaviour of any private methods in
the super class.

Exactly. Sorry for being picky, I guess you meant the right thing but
the wording seemed a bit off.

Kind regards

robert
 
C

Chris Uppal

Mark said:
It is also visible to nested/inner classes of the declaring class.

....and to any classes which enclose it.

But only in the sense that the compiler fakes access by generating non-private
backdoor access methods. That may be close enough for some purposes, but it
turns my stomach.

BTW, /inheritance/ as opposed to just /access/ is a different story. The
reader is invited to consider what the output of the following program should
be according to the spec, what it should be according to common-sense, and what
it will be according to the code generated by javac (I'm using JDK 1.6.0).

-- chris

================
public class Test
{
public static void
main(String[] args)
{
Nested n = new Nested();
n.test();

Test t = new Nested();
t.doIt();
}

private void
doIt()
{
System.out.println("Doin' it");
}

public static class Nested
extends Test
{
public void
test()
{
this.doIt();
super.doIt();
}

public void
doIt()
{
System.out.println("Not gonna do it");
}
}
}
================
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,434
Messages
2,571,685
Members
48,796
Latest member
Greg L.

Latest Threads

Top