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,050 points
319 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 parth295
• 4,640 points

Related Questions In Java

0 votes
0 answers
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,190 points
686 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,150 points
176 views
0 votes
2 answers

What is the difference between Set and List in java?

LIST SET Duplicates YES NO Order Ordered Depends on Implementation Positional Access YES NO List is an ordered sequence ...READ MORE

answered Aug 14 in Java by Sirajul
• 40,990 points
170 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,050 points
68 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,880 points
1,579 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,880 points
77 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 in Java by Sirajul
• 40,990 points
101 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,050 points
74 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 parth295
• 4,640 points
76 views