1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
nika2105 [10]
3 years ago
10

EX 4.11 Suppose you have a class called Child with an instance data value called age. Write a getter method and a setter method

for age.
Computers and Technology
2 answers:
Vika [28.1K]3 years ago
7 0
<span>public void setAge(int new_Age) {
    age = new_Age;
<span>}

public int getAge(){
    return age;
}</span></span>
garri49 [273]3 years ago
3 0

Answer:

public int getAge(){

   return this.age;

}

public void setAge(int age){

    this.age = age;

}

Explanation:

<em>The above code snippet has been written in Java.</em>

The given instance variable, age, is of type int which stands for integer.

<u>Getter method</u>

The getter method will return the instance variable in question. In naming a getter method, the convention is to write 'get' followed by the name of the instance variable, which is 'age' in this case as follows:

                getAge()

getAge() has no parameter and it has a return type of int which denotes the data type of the instance variable in question, age in this case. The complete method declaration for getAge which returns the instance variable, age, is written as follows:

public int getAge(){

   return this.age;

}

<u>Setter method</u>

The setter method will assign a value to the instance variable in question. In naming a setter method, the convention is to write 'set' followed by the name of the instance variable, which is 'age' in this case as follows:

                setAge()

setAge() has one parameter of type int, which is the value to be assigned to the instance variable age, and it has a return type of void which shows that method need not return a value. The complete method declaration for setAge which assigns a value to the instance variable, age, is written as follows:

public void setAge(int age){

    this.age =  age;

}

<em><u>PS: Complete code including the class</u></em>

<em><u /></em>

public class Child{

  int age;    //  instance variable age

public int getAge(){       // getter method for age

   return this.age;

}

public void setAge(int age){    // setter method for age

    this.age = age;

}

}

<em>Hope this helps!</em>

You might be interested in
1
g100num [7]
Have a look at the man page for printf:

man 3 printf
4 0
4 years ago
Read 2 more answers
The __is the temporary storange location for text when it is cut from a document
enot [183]
The informal answer to your question is "clipboard". However, there isn't such a thing as the "clipboard". The people who came up with the idea of the clipboard use that nomenclature to describe the location in memory where that copied data resides. So the formal answer to your question is memory or RAM.
3 0
3 years ago
Which best describes how computer simulations are used in science?
xz_007 [3.2K]
Computer simulation is just like training for example before pilot fly plane they got training from computer simulation it's just like video lecture
5 0
3 years ago
Why are duplicate tuples not allowed in a relation?
velikii [3]

Answer:

Explanation:

Duplicate tuples are not allowed in a relation because the specifications of the constraints of the regional integrity are violated, especially the main constraint that states that there can be no identical values for the attributes of two tuples at any database relation state.

Also, duplicate tuples are not allowed in a relation due to the fact that they lead to redundancy of the data base which in turn, slowing down the speed of the database when data processing such as inserting, querying, updating, deleting, etc are being performed.

4 0
4 years ago
What are the main techniques used to help manage test anxiety? Check all that apply.
Aleks04 [339]

Answer:

1) Avoid the perfectionist of trap

2)Banish the negative thoughts

3) Get enough sleep

4) Make sure you are prepared

5) take deep breaths

Explanation:

In my thought it's the answer of this question.

4 0
3 years ago
Read 2 more answers
Other questions:
  • Give two reasons why it is important to upgrade your browser when a new version becomes available.
    8·1 answer
  • How can you logout your account and do not want to have this anymore
    12·2 answers
  • Markup is best defined as
    11·1 answer
  • Select the correct answer.
    5·2 answers
  • Solve the recurrence relation.<br> S(1)=1<br> S(n)= S(n-1)+(2n-1) for n&gt;=2
    13·1 answer
  • An element in an array is 4 bytes long and there are 10 elements in the array. How big is the array?
    6·2 answers
  • Convert 578.2 into hexadecimal​
    9·1 answer
  • What is something that can be done to help stop teen teen crashes
    8·1 answer
  • drag each type of document to the correct location on the table. Drag each document to its respective category
    7·1 answer
  • a computer technician performed a number of actions to correct a problem. some actions did not solve the problem, but eventually
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!