• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

abstract class

 
Krishna Tota
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2854
10
Fedora Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Amit Ghorpade
Bartender
Posts: 2854
10
Fedora Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And Krishna Tota please UseAMeaningfulSubjectLine.
"abstract class" makes very little sense.
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2854
10
Fedora Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 117
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Amit and Ronald
 
Amit Ghorpade
Bartender
Posts: 2854
10
Fedora Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are welcome
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic