aspose file tools*
The moose likes Beginning Java and the fly likes abstract class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "abstract class" Watch "abstract class" New topic
Author

abstract class

Krishna Tota
Ranch Hand

Joined: Mar 22, 2008
Posts: 40
Hi,
Can an abstract class contains private members?if yes,how these menbers can be accesed?And i know private members are accesed with in the class.

please explain in brief.
Thanks.
Shyam Sunder V R
Greenhorn

Joined: Jul 29, 2008
Posts: 20
Hi krishna,
As far as I know the abstract methods should not be declared private because however some class is gonna subclass it and should be implementing it.But ,the variables can be declared private.
CORRECT ME IF I AM WRONG.
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

Originally posted by Krishna Tota:
Can an abstract class contains private members?if yes,how these menbers can be accesed?


yes,abstract class can have private member. but it is meaningless.

Note:Abstract class is designed to be a public place .
Amit Ghorpade
Bartender

Joined: Jun 06, 2007
Posts: 2716
    
    6

Hi Shyam Sunder V R welcome to Javaranch,
looks like your name does not follow the Javaranch Naming policy.
Please change it here.

Can an abstract class contains private members?

yes both variables and methods.

Originally posted by seetharaman venkatasamy
yes,abstract class can have private member. but it is meaningless.

Why


SCJP, SCWCD.
|Asking Good Questions|
Amit Ghorpade
Bartender

Joined: Jun 06, 2007
Posts: 2716
    
    6

And Krishna Tota please UseAMeaningfulSubjectLine.
"abstract class" makes very little sense.
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

Originally posted by Amit Ghorpade:

Why


Hi amit, if abstract method has private method ,what is the use of that method[if it has private variable ,ok ]

correct me,if i am wrong
Amit Ghorpade
Bartender

Joined: Jun 06, 2007
Posts: 2716
    
    6

if abstract method has private method ,what is the use of that method


If abstract class has private methods, other non abstract methods or public methods can still call them.
This is similar to having private constructors.



Hope this helps
Ronald Schild
Ranch Hand

Joined: Jun 09, 2008
Posts: 117
For the sake of the implementation of non abstract methods in an abstract class.

Let's say you have your abstract class:


You can subclass this class and use iDoSomethingUsefulThatYouInherit() at will, while for it's implementation you have used private members.
[ July 30, 2008: Message edited by: Ronald Schild ]

Java hobbyist.
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

Thanks Amit and Ronald
Amit Ghorpade
Bartender

Joined: Jun 06, 2007
Posts: 2716
    
    6

You are welcome
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: abstract class