Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

What is the difference between the public and private keywords? a. O Public memb

ID: 3592374 • Letter: W

Question

What is the difference between the public and private keywords? a. O Public members are usable only in Java, while private members are usable in other programming languages. b. O A class can be public, private, or both, depending on the situation. c. OThe public keyword can only be used on methods, and the private keyword can only be used on fields. d. O Items declared public may be seen and used from any class, while items declared private may be seen and used only from within their own class. e. O Public fields can be seen in two Java programs at a time while private fields can be seen in only one Java program (order shuffled) What items should be declared private? a. O All instance methods should be private to keep them from being called by malicious clients, for better security. b. O Fields and constructors should both always be private, but methods should always be public. c. O Classes should be declared private, but methods and fields should be public. d. O Objects' fields should be declared private to provide encapsulation, so that external code can't make unwanted direct noheant feid of a ciass should be private, bu e. O The most important field of a class should be private, but the other less important fields can be public. (order shuffled)

Explanation / Answer

Question :  what is the difference between public and private keywords?

a.Public members are usable only in Java, while private members are usable in other programming languages.

b. A class can be public, private, or both, depending on the situation.

c. The public keyword can only be used on methods, and the private keyword can only be used on fields.

d. Items declared public may be seen and used from any class, while items declared private may be seen and used only from within their own class.

e. Public fields can be seen in two Java programs at a time while private fields can be seen in only one Java program.(order shuffled)

ANSWER : Option - (D) -- Items declared public may be seen and used from any class, while items declared private may be seen and used only from with in their own class

Explanation :

public members of class can be accessed by any code in the program.
private members of class can only be accessed by other members of the class.

a. All instance methods should be private to keep them from being called by malicious clients, for better security.

b. Fields and constructors should both always be private, but methods should always be public.

c.Classes should be declared private, but methods and fields should be public

d. Objects' fields should be declared private to provide encapsulation, so that external code can't make unwanted direct modifications to the fields' values.

e. The most important field of a class should be private, but the other less important fields can be public.

(order shuffled)

ANSWER: OPTION (D)

EXPLANATION:

All instance methods cannot be private it can also be protected from being called by malicious clients,for better security.

a.Public members are usable only in Java, while private members are usable in other programming languages.

b. A class can be public, private, or both, depending on the situation.

c. The public keyword can only be used on methods, and the private keyword can only be used on fields.

d. Items declared public may be seen and used from any class, while items declared private may be seen and used only from within their own class.

e. Public fields can be seen in two Java programs at a time while private fields can be seen in only one Java program.(order shuffled)

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote