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
otez555 [7]
2 years ago
11

write a method that will return a person's age entered by keyboard. You will need to include at least one instance variable in t

his program. No parameters are necessary for this question. You must NOT print out the age from within the return method but rather from another method. in java =D
Computers and Technology
1 answer:
slamgirl [31]2 years ago
4 0

Answer:

This JAVA program shows the implementation of instance variable and methods.

import java.util.Scanner;

import java.lang.*;

public class Person {    

   Scanner sc = new Scanner(System.in);    

   // instance variable declared without static keyword and outside of all methods

   int age;    

   void getAge()

   {

       System.out.println("Enter your age");

       age = sc.nextInt();

   }    

   void display()

   {

       System.out.println("Entered age is " + age);

   }    

   public static void main(String args[]) {        

       Person ob = new Person();        

       ob.getAge();

       ob.display();

   }

}

OUTPUT

Enter your age

45

Entered age is 45

Explanation:

A class contains its own variables and methods. An instance variable is declared inside the class and outside of all the methods contained in that class.

As specified in the question, the class Person contains one instance variable age and two methods, along with main() method.

Along with the instance variable age, an object of the Scanner class is created to enable input from the user. Both these variables are outside the methods. To enable user input, the required java package has been imported.

The two methods are defined to receive age and display age as mentioned in the question.

The input age is stored in the instance variable age.

void getAge()

   {

       System.out.println("Enter your age");

       age = sc.nextInt();

   }

This variable is used in display() to print the age.

void display()

   {

       System.out.println("Entered age is " + age);

   }

   

All the methods are contained in a single class. Despite this, other methods can only be called through the object of the class which shows that JAVA is purely object oriented language.

public static void main(String args[]) {

       

       Person ob = new Person();

       

       ob.getAge();

       ob.display();

   }

As seen, the instance variable can be used by all methods contained in that particular class. The object of the class is only needed to call the method and not needed to use the instance variables.

You might be interested in
Each of the outcomes listed below is a result of executing the following script except for one. Which one? CREATE ROLE ExampleRo
Vinil7 [7]

Answer:

Option (A) is the correct answer to the following question.

Explanation:

The following option is correct because with the help of the database we can create the table and the user would be given the permission of INSERT, UPDATE the table and also give permission to SELECT all user tables.

The option B is incorrect because the following table can get permission to input to the vendor's table.

The option C is incorrect because we can be assigning to the role db_datareader.

4 0
3 years ago
What is information technology
GalinKa [24]

Answer:

nformation technology is the use of computers to store, retrieve, transmit, and manipulate data or information. IT is typically used within the context of business operations as opposed to personal or entertainment technologies. IT is considered to be a subset of information and communications technology

8 0
3 years ago
What are the only things that can be declared in an interface?
Helga [31]
In c# you can declare properties and methods, not fields though
6 0
3 years ago
Discuss in detail why you need to use a write blocker (either hardware or software) in your examinations, whether for a criminal
dolphi86 [110]

A write blocker is any tool that permits read-only access to data storage devices without compromising the integrity of the data. A write blocker, when used properly, can guarantee the protection of the data chain of custody. NIST‘s general write blocking requirements hold that:

<span>The tool shall not allow a protected drive to be changed.The tool shall not prevent obtaining any information from or about any drive.<span>The tool shall not prevent any operations to a drive that is not protected.</span></span>
8 0
3 years ago
What information will she need to know in order to obtain assistance from the chief medical officer to reduce the number of deli
Serga [27]

The information that she need to know in order to obtain assistance from the chief medical officer to reduce the number of delinquent records is the Discharge Record Assembly .

What is  an incomplete health record or a delinquent health record?

An  incomplete health record is one that is often open after a set period of time such as more than 30 days and if not complete, the health record is said to be delinquent.

Note that Nurses are mandated to carefully maintain patient records. Therefore, The information that she need to know in order to obtain assistance from the chief medical officer to reduce the number of delinquent records is the Discharge Record Assembly .

Learn more about chief medical officer from

brainly.com/question/18696862

#SPJ1

6 0
1 year ago
Other questions:
  • What important information is added to the TCP/IP transport layer header to ensure communication and connectivity with a remote
    13·1 answer
  • Write a function max arguments. write a program that reads three floating-point numbers, uses the max function, and displays the
    5·1 answer
  • A retail company must file a monthly sales tax report listing the total sales for the month and the amount of state and county s
    11·1 answer
  • Which device makes computers that are connected to separate segments appear and behave as if they're on the same segment? (Pleas
    11·1 answer
  • Which option describes wearable technology?
    9·1 answer
  • What is the Matlab command to create a column vector with 11 equally spaced elements, whose first element is 2 and whose last is
    8·1 answer
  • Write a program that reads from the user any three points in two dimensional space: x1, y1, x2, y2, x3, y3. Assume these points
    13·1 answer
  • The most important hardware device for connecting supercomputers over a wide area
    10·1 answer
  • . Question 2 Fill in the blank: R Markdown notebooks can be converted into HTML, PDF, and Word documents, slide presentations, a
    9·1 answer
  • Why do you want to work from our company?​
    9·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!