Java Assignment writing Help from Tutorspoint

Tutorspoint.com is an excellent site, which caters to all queries regarding java assignments of student and provides quality solutions. The student finds complex idea and terms easy to comprehend.

Since the Java Assignment writing help is offered at reasonable rates, TutorsPoint is highly recommended by students worldwide especially in America, Australia, United Kingdom countries 

Definition of Access specifiers

Access specifiers are keywords which mention about the accessibility of contents of a class, somewhere outside of the class. There are four types of access specifiers are available.

  • Public
  • Private
  • Protected
  • Default

Here public, private, protected are keywords. When none of these is used, then the access specifier of that particular statement or block would be the default (there is no keyword for the default access specification).

Public:

Keyword specifies that the accessibility is global.

Private:

Keyword specifies that the accessibility is confined to that class.

Protected:

The behavior of this access specifier is also similar to default but with a small difference. Default would be acting as private outside the packages. Same is the case with protected. But the difference is protected would behave as public with respect to subclass objects even outside the packages.

Default:

Default is similar to public as long as the control is in the same package else default acts as private.

Example Program:

Class access 1

{

Public int I;

Private int j;

Public void function A ()

{

I = i+1;

System. Out. Prinln(i);

System. Out. Prinln(j);

}

Private void function B ()

{

I = i*I;

J = j*j;

System. Out. Prinln(i);

System. Out. Prinln(j);

}

Public static void main (string args [ ])

{

Access a1 = new Access 1();

a1. Function A ();

a1. Function B ();

System. Out. Prinln(a1 .j);

}

}

Class test

{

Public static void main (string args [ ])

{

Access a1 = new Access 1();

a1. Function B (); \\ compilation error: fun B() is private and can be accessed only with class access.

System. Out. Prinln(a1 .i); \\ I is public and is accessible everywhere i=0.

System. Out. Prinln(a1 .j); \\  j is private

a1. Function A (); \\ no error, even though fun A () is accessing private members.

}

}

Difference between public and default access specifiers:

Default would be similar to public as long as the .class files are in the same package (i.e. same path) outside the packages the default accessibility would be similar to private.

Access Specifiers Homework Help