Ask Question
14 December, 01:41

Print person1's kids, call the incNumKids () method, and print again, outputting text as below. End each line with a newline. Sample output for below program with input 3:

+5
Answers (1)
  1. 14 December, 04:52
    0
    The program to this question can be given as follows:

    Program:

    class Person_details

    {

    int num_Kids; / /defining integer variable

    void Set_Num_Kids (int persons_Kid) / /defining method set_Num_Kid

    {

    num_Kids = persons_Kid; //holding value in num_Kids variable

    }

    void incNumKids () / /defining method incNumKids

    {

    num_Kids = num_Kids + 1; / /incresing value of num_Kids variable by 1

    }

    int get_Num_Kids () / /defining method get_Num_Kids

    {

    return num_Kids; //return value of num_Kids variable

    }

    }

    public class Main / /defining class Main

    {

    public static void main (String [] args) / /defining main method

    {

    int persons_Kid=3; / /defining integer variable persons_Kid

    Person_details p1 = new Person_details (); / /creating Person_details class Object

    p1. Set_Num_Kids (persons_Kid); / /calling method Set_Num_Kids.

    System. out. println (p1. get_Num_Kids ()); / /calling get_Num_Kids method and print value

    p1. incNumKids (); / /calling incNumKids method

    System. out. println (p1. get_Num_Kids ()); //calling get_Num_Kids method and print value

    }

    }

    Output:

    3

    4

    Explanation:

    In the above program code, two-class is defined that are "Person_details and Main", inside the Person_details class one integer variable num_Kids, and three method that are "Set_Num_Kids, incNumKids, and get_Num_Kids" is defined, in which first two method is used to hold a value and the third method is used for return a value.

    Then the Main class is defined, inside this class main method is declared, in this method, an integer variable persons_Kid is defined, that holds a value that is "3". In the next line, Person_details class object is created and call function and to print return function value the print function is used.
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “Print person1's kids, call the incNumKids () method, and print again, outputting text as below. End each line with a newline. Sample output ...” in 📙 Engineering if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers