answersLogoWhite

0


Best Answer

One of the techniques in object-oriented programming is encapsulation. It concerns the hiding of data in a class and making them available only through its methods. In this way the chance of making accidental mistakes in changing values is minimized. Java allows you to control access to classes, methods, and fields via so-called access modifiers. The access to classes, constructors, methods and fields are regulated using access modifiers i.e. a class can control what information or data can be accessible by other classes. To take advantage of encapsulation, you should minimize access whenever possible.

Java provides a number of access modifiers to help you set the level of access you want for classes as well as the fields, methods and constructors in your classes. A member has package or default accessibility when no accessibility modifier is specified.

Access Modifiers

1. Private

2. Protected

3. Default

4. Public

Public is the most liberal access modifier and Private is the most restrictive access modifier. NB there is no such thing as an 'access specifier' in Java, only access modifiers.

User Avatar

Wiki User

13y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

14y ago

In java we can have 4 diff.. type of access specifiers they are 1.Default, 2.public 3.protected 4.private

public: provide access to classes, methods and fields from every other class.

Default: it must not be written and provide access to classes, methods and fields only from classes in the same package.

protected: it is mostly the same as the default access specifier, but you can't mark a class as protected. The only difference is in the inheritance.

private: prevent methods and field to be accesses from any other class.

This answer is:
User Avatar

User Avatar

Wiki User

14y ago

default,private, public,protected

default its a default access specifier decided by java compiler

private its does not allow any another class to access its private data members and methods

public subclass can access all data members of super class if they are public

protected only subclass of superclass can access datamembers

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Define access specifiers in object oriented programming?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

What are the access specifiers in c?

Satya


What are the various access specifiers?

Three types of access specifier private , public ,protected


What is the need of using access specifiers?

To ensure that the variables and methods are used only by the necessary classes/methods. If we are going to declare a method or a variable public, it can be accessed by everybody thereby making it vulnerable to unwanted change by other classes. If we make it private, only that class can modify it and hence data is secure. The above is just a simple example of how useful access specifiers are in programming.


What do you mean by access specifier in c?

There are no access specifiers in C. All functions and data are public.


How does C programming give access to low level memory?

Define 'low level memory' first.


Why is object-oriented programming advantageous over other techniques?

advantages of object oriented programming over other techniques 1. Reusability of code 2. Easy to access class properties, methods through object 3. Runtime processing based on input values


What are access specifiers in programming?

Access specifiers are used in object oriented programming to define public, protected and private interfaces. In non-object oriented languages, everything has public access. While this gives great freedom to the programmer, it makes it difficult for the programmer to maintain invariants. When distributing code, the onus is upon the consumer to observe those invariants and adhere to them. But the language will not assist them because invariants are typically established through user-defined comments which the compiler completely ignores. Using access specifiers, the programmer can define an interface that ensures correct behaviour at all times. The onus of responsibility then shifts to the language itself. While this restricts consumer freedom, the restriction is intended to make objects easier to use without imposing any unnecessary limitations. The consumer is only granted access to what they actually need to access. Anything that could potentially violate an invariant is safely encapsulated within the object itself. If the consumer has access to the source code, they can easily examine the implementation should they wish to do so, but with a well-defined public interface, it is not necessary to know the private implementation details. Access specifiers apply members of a class which includes base classes. Private members are only accessible to the class itself and to friends of the class (friendship can only be granted by the class itself). Protected members are the same as private members, but are also accessible to derivatives of the class. Public members are accessible to any code. Derivatives can also change the access specifiers of their bass class members, but they can only reduce access; they can never increase it. In this way, class designers can ensure that objects of their class behave in a highly predictable manner. Consumers cannot break invariants encapsulated by a class, thus class implementations can be greatly simplified compared to public code, thus reducing the amount of code that needs to be generated. There is no need to constantly check an invariant holds because only the code that directly affects an invariant (constructors and mutators) also maintains that invariant. Class methods that simply grant access to object information (accessors) do not affect the invariant, so no error-checking is required; if the object exists, its invariant is assured to hold.


Do you get Security by access specifiers in Java?

No, because there is no such thing as an access specifier in Java. There are access modifiers, and security is their entire purpose, so of course you get it when you use them.


What are different access specifiers in c sharp?

public private internal protected internal protected


Explain the different access storage specifiers available in c?

The storage class specifiers in C and C++ are:autoexternmutableregisterstatictypedefA storage class specifier is used to refine the declaration of a variable, a function, and parameters


Advantage of object oriented programmings?

Some advantages of object oriented programming are: a. The code is easier to organize and maintain b. Chances of logic errors are reduced c. Code redundancy is avoided because of inheritance d. Unwanted code access is avoided by using access modifiers and encapsulation e. Etc.


What is friend datatype in object-oriented programming?

A friend is any class, class method or function that is declared to be a friend of a class. Friends have private access to the classes that declare them friends.