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,120 points
1,349 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,630 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,110 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
15,155 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,638 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
62,639 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,120 points
980 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,910 points
33,199 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,910 points
940 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,025 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,120 points
1,068 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,630 points
750 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