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,040 points
172 views

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
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,600 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
385 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
88 views
0 votes
1 answer

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,150 points
38 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,040 points
36 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,840 points
369 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,840 points
47 views
0 votes
1 answer

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

Use java.time classes instead of java.util.Date & java.sql.Date with JDBC 4.2 or ...READ MORE

answered Jun 29, 2018 in Java by Sushmita
• 6,840 points
60 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,040 points
28 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,600 points
40 views

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.