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]
3 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]3 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
Describe your previous personal or professional experience with Microsoft Word.
Stolb23 [73]

Answer:

Microsoft Word is pretty helpful.

Explanation:

I go to school and at school I have projects with Microsoft Word and it's pretty easy to understand. I'd recommend.

8 0
3 years ago
Why did Herman Hollerith invent the Tabulating Machine?
Anvisha [2.4K]

Answer:

the machine was developed to help process data for the 1890 U.S. Census.

Explanation:

U.U

8 0
3 years ago
Explain briefly why it is sometimes necessary to roll software back to a previous version, a procedure called "software
Travka [436]

Answer:

If there is some sort of error

Explanation:

If there is an error that is causing problems for clients that needs to be worked out still, rolling back allows customers to still do whatever they need while you look for a solution in the new version.

7 0
3 years ago
The Operating System is used to locate, move, and copy files.
Temka [501]

Answer:

Yes!! the operating system is used to locate, move, and copy file

7 0
3 years ago
Re:
aksik [14]

Answer:

A) create new records

B) open and close forms

C) open database forms

F) navigate through records

G) import and export data

Explanation:

5 0
3 years ago
Other questions:
  • Assume that an int variable age has been given a value. Assume further that the user has just been presented with the following
    14·1 answer
  • Why Unicode is the standard way of converting binary to text?
    8·1 answer
  • If num is an int which expression always evaluates to true if num holds an odd number
    14·1 answer
  • In which type of land contract does the seller earn interest on the difference between what the seller owes on an existing loan
    14·1 answer
  • If you cause a car accident, which type of insurance will require you to pay the least out of pocket?
    5·2 answers
  • What is the traditional cognitive perspective ofHCL?
    12·1 answer
  • Suppose that a is declared as an int a[99]. Give the contents of the array after the following two statements are executed: for
    15·1 answer
  • kieran wants to search a database quickly for information on the last time a patient came to his medical facility.The informatio
    14·2 answers
  • What steps should a user take to create a secondary address book?
    8·2 answers
  • What are the purposes of a good web page design?
    9·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!