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
A(n) ________ is usually a live broadcast of audio or video content. Select one: A. instant message B. webcast C. podcast D. wik
navik [9.2K]

Answer: B webcast

Explanation:

A webcast is a technology that allows the live broadcast of an audio or video event on the Internet. It is also known as Web lecture, virtual meeting, etc. The major advantage is that it gives room for an event to have a larger reach. Webcast participation can be through PC, smart phones, tablets and other devices with quality Internet access.

7 0
3 years ago
Read 2 more answers
Whats the best apex legend?
Ugo [173]

Answer:

Apex Legends combines royal genre products and hero-shooters for something fantastic like Overwatch. Please note that you've got one of the smoothest, snappest and most satisfying royal battle games since Fortnite and PUBG (the ex-callof duty developers) by the same team as the Titanfall franchise. Apex Legends is really characterized by its diverse range of characters and unique skills. While everyone is still subject to identical weapons, grenades and health packs, they can turn the tide of fighting quickly. Don't go in on your legends without brushing them. Here are all the characters ranked in Apex Legends.

Explanation:

Lifeline. Lifeline.

Skull. There was a mistake.

Octane.-Octane. There was a mistake.

Pathfinder.-Pathfinder. There was a mistake.

Bloodhound.-Bloodhound. Bloodhound is next up. Next up. There was a mistake.

Gibraltar.-Gibraltar. The ultimate of GIbraltar is amazing and it matches up well with his globe. There was a mistake.

Wonder. Wonder. Mirage is still in the bottom of Legends, one of my favorite characters in the game. There was a mistake.

Awkward. We've got Caustic at the bottom of the list. There was a mistake.

4 0
3 years ago
Read 2 more answers
If a menu item requires additional information from the user, the Windows standard is to place a(n) ____ at the end of the capti
elena-s [515]

Answer:

elipses

Explanation:

According to my research on information technology, I can say that based on the information provided within the question the windows standard in this situation would be to place an ellipses at the end of the caption. This is because in the English language an ellipses (...)  usually indicates an intentional omission of a word or sentence, which in computer science is used to give the user an indication that it requires further user input.

I hope this answered your question. If you have any more questions feel free to ask away at Brainly.

4 0
3 years ago
Of the choice below,access to with tab will start a power point presentation
kow [346]

the menu and the toolbars
4 0
3 years ago
Elliott is trying to normalize a database that he has designed. Which is not one of the elements of 1NF or 2NF?
muminat

Answer: I think it’s D

Explanation: the rest apply to the the rules of 1NF and 2NF

5 0
3 years ago
Other questions:
  • What is an example of a good URL?
    7·2 answers
  • This term describes two or more arrays that hold related data, and the related elements in each array are accessed with a common
    15·1 answer
  • What is the primary means by which attackers infect computers with these attacks? How do these attacks commonly occur?
    8·1 answer
  • 2.13 LAB: Branches: Leap Year
    11·1 answer
  • What is the cpu used for
    6·1 answer
  • Please help and answerr
    8·1 answer
  • How to enhance the video to full screen in filmora
    15·1 answer
  • 5 differences between a regular mouse and a gaming mouse​
    14·1 answer
  • In a paragraph discuss 5 steps of saving a document in a storage device.<br>​
    5·1 answer
  • Which of the following terms refers to the area of the hard drive used for virtual memory?
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!