Public class Person String name String Telephone String email // class methods…

2023

Public class Person
String name
        String Telephone
        String email
        // class methods
        initialise( )
        // code for initialise
        Public Print( )
        Public Name Getname( )
                return Name
        Public String Getemail( )
                return email
        Public String Gettelephone( )
                return Telephone
What will be access specifier of the field of the above class?

  1. A.

    Public

  2. B.

    Private

  3. C.

    Public-private

  4. D.

    None of these

  5. E.

    Question not attempted

Attempted by 138 students.

Show answer & explanation

Correct answer: D

Solution:

Correct Answer: None of these

Given code:

String name;
String Telephone;
String email;

In Java, access modifiers define the visibility of class members. The main access levels are:

  • public

  • private

  • protected

  • default (package-private)

In the given code, no access modifier is written before the fields name, Telephone, and email.

When no access modifier is specified in Java, the member gets the default access level, also called package-private access.

Hence, the fields are neither public nor private.

Therefore, the correct answer is:

None of these

Difference between Private and Package-Private:

  1. Private Access

  • Declared using the private keyword.

  • Accessible only within the same class.

Example:

private String name;
  1. Package-Private (Default Access)

  • No keyword is written.

  • Accessible by all classes within the same package.

Example:

String name;

Important Note:

From an Object-Oriented Programming design perspective, fields are usually kept private to support encapsulation and accessed through getter/setter methods. However, technically, the given code uses package-private access because no modifier is explicitly written.

Explore the full course: Up Lt Grade Assistant Teacher 2025