Describe the four levels of access protection, JAVA Programming

Assignment Help:

Describe the Four Levels of Access Protection ?

Any two various Java objects have one of four relations to each other. The four relations are:
• The objects are in the similar class.
• One object is a subclass of the other object's class.
• The objects are in the similar package.
• None of the above. (Both objects are members of the general public.)

These relationships are not mutually exclusive. One object could be a subclass of another object in the similar package, for example.
You can describe that of your class's members that is its fields and its methods, are accessible to other objects in each of these four groups, associative to the current class.

If you need any object at all to be able to call a techniques or change a field, declare it public.
If you want only objects in the similar class to be able to get or set the value of a field or invoke a method, declare it private.
If you need access restricted to subclasses and members of the similar package, declare it protected.
At last, to restrict access only to objects in the similar package, use no access declaration at all. This is known as "package" or "default" access, but it has no keyword. The default keyword means something else whole.
Can anyone remember what?

By default, all classes you write are in the similar package. Therefore, they are in different packages from the Java classes like System or Applet.

The public fields and techniques of an object can be accessed from anywhere the object itself can be seen. Anyone can touch an object's public members. They should be kept to a minimum. Public fields should associate very closely to the core functionality of the class. They should not show intimate details of the inner workings of the class. Except in very simple instances fields should probably not be public.

The private fields and methods of an object can only be accessed by the object itself and by other objects of the same class (siblings). An object may touch its sibling's private parts. A sibling is an object in the same class but which is not the same object.


Related Discussions:- Describe the four levels of access protection

Write output for the given code of for loop, What is the output of the foll...

What is the output of the following code: for (i=0; i { document.write("The number is " + i); document.write(" "); } Output The number is 0 The number is 1 The number i

Arrays, Prompt the user for an int between an upper and lower boundary. Reu...

Prompt the user for an int between an upper and lower boundary. Reuse the validateInput() method from project 2 to validate if the input is in bounds. If it is not, print an error

Event handler, search a file with specific extension

search a file with specific extension

Write a program on clearing rectangles, Write a program on clearing Rectang...

Write a program on clearing Rectangles ? It is also potential to clear a rectangle that you've drawn. The syntax is exactly what you'd expect: public abstract void clearRect

Arithmetic, 1-4 Problem Set: Arithmetic Consider the following statement wh...

1-4 Problem Set: Arithmetic Consider the following statement when responding to questions 1 and 2: Jim develops 5 Java applications a year. Joe develops 10 Java applications a year

Program to find prime number from linked list, For this assignment you are ...

For this assignment you are provided with a class called LNode which can be used as a list node for a linked list of ints. You are also provided with an abstract class called LList

Explain the concept of multi-threaded- java, Explain the concept of Multi-T...

Explain the concept of Multi-Threaded- JAVA Java has a concept of concurrency wired right in to the language itself. This works out more cleanly than languages where concur

Program that receives two integer inputs from a user, Question 4 Write ...

Question 4 Write a program that receives two integer inputs from a user, an ending value, lastvalue and column, column. The program will display all numbers from 1 to lastvalue

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd