• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

abstract class

 
Krishna Tota
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 2856
10
Firefox Browser Fedora Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 2856
10
Firefox Browser Fedora Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And Krishna Tota please UseAMeaningfulSubjectLine.
"abstract class" makes very little sense.
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 2856
10
Firefox Browser Fedora Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Amit and Ronald
 
Amit Ghorpade
Bartender
Posts: 2856
10
Firefox Browser Fedora Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You are welcome
 
Hey, sticks and stones baby. And maybe a wee mention of my stuff:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic