Expert Solution & Answer
Book Icon
Chapter 5.2, Problem 21STQ

Explanation of Solution

Defining a “private” method:

  • The method should be in “private” if a method used only within the definitions of other methods of the same class.
    • So, user can access the “private” method within the same class definition.
  • User cannot access the “private” method in any other class.

Example:

The example for defining a private method is shown below:

Filename: “sampleProgram.java”

//Create "sampleProgram" class

public class sampleProgram

{

    //Method definition for sampleMethod1

    public void sampleMethod1()

    {

/* Call the method sampleMethod2(). It is private method in the "sampleProgram" class */

        sampleMethod2();

        //Display message

        System.out.println("Sample Method 1");

    }

    //Method definition for sampleMethod2

    private void sampleMethod2()

    {

        //Display message   

        System.out.println("Private Sample Method");

    }

}

Filename: “Main...

Blurred answer
Students have asked these similar questions
Python - Need help! How do I have an input in turtle to display my name below the circle it draws and another input to display my age written below that? Code: import turtlebackground = "#FFFFFF" def draw_circle(radius, line_color, fill_color):    my_turtle.color(line_color)    my_turtle.fillcolor(fill_color)    my_turtle.begin_fill()    my_turtle.circle(radius)    my_turtle.end_fill() def move_turtle(x, y):    my_turtle.penup()    my_turtle.goto(x, y)    my_turtle.pendown()   turtle.done()
Need help fixing my python code! Images attached on the required modficications I dont know how to do. Simpler the better.Code: (in images)
Answer all of the questions with steps by step explanation to every question.

Chapter 5 Solutions

Java: An Introduction To Problem Solving And Programming Plus Mylab Programming With Pearson Etext -- Access Card Package (8th Edition)

Knowledge Booster
Background pattern image
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,
Text book image
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage
Text book image
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Text book image
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781305480537
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Text book image
CMPTR
Computer Science
ISBN:9781337681872
Author:PINARD
Publisher:Cengage
Text book image
New Perspectives on HTML5, CSS3, and JavaScript
Computer Science
ISBN:9781305503922
Author:Patrick M. Carey
Publisher:Cengage Learning