What is the difference between package private public protected

0 votes
Are there rules to on when to use which access specifier for the package?
May 24, 2018 in Java by Daisy
• 8,140 points
1,551 views

1 answer to this question.

0 votes

Modifier

Class

Package

Subclass

World

Public

Y

Y

Y

Y

Protected

Y

Y

Y

N

No modifier

Y

Y

N

N

private

Y

N

N

N

 

Public: Any package, any class accessibility is available
Private: Access is not available outside the class
Protected: When an attribute of a method is declared as protected then it is visible to all the classes in the same package and all subclasses in different package
answered May 24, 2018 by Parth
• 4,640 points

Related Questions In Java

0 votes
0 answers

What is the difference between Default and Protected access specifiers?

Can anyone explain in brief as what ...READ MORE

Feb 6, 2019 in Java by Dishantu
1,272 views
0 votes
2 answers

What is the difference between implements and extends?

Extends : This is used to get attributes ...READ MORE

answered Aug 3, 2018 in Java by samarth295
• 2,220 points
16,129 views
0 votes
1 answer

What is the difference between jdk and jre?

JRE: It stands for Java Runtime Environment. ...READ MORE

answered Apr 20, 2018 in Java by Akrati
• 3,190 points
1,925 views
0 votes
2 answers

What is the difference between Set and List in java?

List is an ordered sequence of elements. ...READ MORE

answered Apr 26, 2018 in Java by Akrati
• 3,190 points
63,314 views
0 votes
1 answer

How to set a timer in Java?

To work on timer in java, you ...READ MORE

answered May 16, 2018 in Java by Daisy
• 8,140 points
1,199 views
0 votes
2 answers

How can I solve java.lang.NoClassDefFoundError in Java?

NoClassDefFoundError means that the class is present ...READ MORE

answered Sep 11, 2018 in Java by Sushmita
• 6,920 points
34,033 views
0 votes
2 answers

Explain the functionality of Math.random() method.

You can use java.util.Random class. int myNumber = ...READ MORE

answered Aug 3, 2018 in Java by Sushmita
• 6,920 points
1,311 views
0 votes
2 answers

How can we convert java.util.Date to java.sql.date in Java?

It's easy to convert a java.util.Date object ...READ MORE

answered Aug 27, 2019 in Java by Sirajul
• 59,230 points
1,305 views
0 votes
2 answers

What is the difference between = and equals()?

The equals() method compares the "value" inside String instances ...READ MORE

answered Aug 13, 2018 in Java by Daisy
• 8,140 points
1,378 views
0 votes
1 answer

How to calculate the difference between two date instances in Java?

You can use Joda Time Library. Interval i ...READ MORE

answered May 4, 2018 in Java by Parth
• 4,640 points
937 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP