1,105,380 Community Members

Public/Private class

corvenzo
Newbie Poster
1 post since Mar 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
Unverified Member
 
0
 

Hi,

I'm a pretty new Java student and I was just confused on a few basic concepts. What exactly is the difference between public and private classes and in which case would you use each one? also, what is a constructor, mutator, or accessor?

Thank you.

Member Avatar
NormR1
Posting Sage
7,723 posts since Jun 2010
Reputation Points: 563 [?]
Q&As Helped to Solve: 793 [?]
Skill Endorsements: 16 [?]
Team Colleague
 
1
 

Take a look at these pages:
[Link Anchor Text](http://docs.oracle.com/javase/tutorial/java/javaOO/classes.html

Member Avatar
stultuske
Posting Expert
5,291 posts since Jan 2007
Reputation Points: 935 [?]
Q&As Helped to Solve: 774 [?]
Skill Endorsements: 35 [?]
Featured
 
0
 

a private class? maybe for inner classes, but I definitely wouldn't recommend it otherwise :)
I think you ment the access modifiers public-protected-private(-package) for the variables?

Member Avatar
JamesCherrill
... trying to help
10,364 posts since Apr 2008
Reputation Points: 2,081 [?]
Q&As Helped to Solve: 1,749 [?]
Skill Endorsements: 47 [?]
Moderator
Featured
 
0
 

a private class? maybe for inner classes, but I definitely wouldn't recommend it otherwise :)

The all-important JLS section 8.1.1 says

The access modifiers protected and private (§6.6) pertain only to member classes within a directly enclosing class or enum declaration (§8.5).

For example you may have a class that represents a collection of Things that you will want to sort in various different orders. You create private member classes for the different Comparators that you use in your sorting.

Member Avatar
ash.28.88
Newbie Poster
8 posts since Sep 2010
Reputation Points: -3 [?]
Q&As Helped to Solve: 1 [?]
Skill Endorsements: 0 [?]
 
0
 

hi,
public amd private are the access modifire.This modifires are allowed on variables,methods and classes.
If we want to access a class anywhere then make this class as public using public keyword.
In the case PACKAGE,public class can be access within the same package or in the other package
But private class can't be access in the same package or in the other package.
Simply we say that public are write once and access anywhere but private can't.

You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: