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
How computational thinking skills impact software design and the quality of the software applications produced?
IRINA_888 [86]

Answer:

 Computational thinking skills basically provide the ability and capability to lean the computer programming language and its also plays an important role in the software designing process. It also helps in improve the quality of various types of software application in programming world.

The computational thinking provide various types of benefits in the software application is that it breaks the complex system problem into the small parts so that it can easily managed.

It helps on focusing only on the important and effective information or data and ignore the irrelevant information in the software designing process and applications.  

5 0
4 years ago
Which is an appropriate strategy for using a workplace blog?
OLEGan [10]

Answer:

a

Explanation:

8 0
3 years ago
To iterate through (access all the entries of) a two-dimensional arrays you
ahrayia [7]

Answer: You would need two loops to iterate through both dimensions

Explanation:

matrix = [[1,2,3,4,5],

              [6,7,8,9,10],

              [11,12,13,14,15]]

for rows in matrix:

    for numbers in rows:

         print(numbers)

The first loop cycles through all the immediate subjects in it, which are the three lists. The second loop calls the for loop variable and iterates through each individual subject because they are lists. So the first loop iterates through the 1st dimension (the lists) and the seconds loop iterates through the 2nd dimension (the numbers in the lists).

6 0
3 years ago
How to clear cache in internet explorer version 11?
adelina 88 [10]
1.Select Tools (via the Gear Icon) > Safety > Delete browsing history....

NOTE: You can also access this menu by holding Ctrl + Shift + Delete.

2.Make sure to uncheck Preserve Favorites website data and check both Temporary Internet Files and Cookies then click Delete.



3.You will get a confirmation at the bottom of the window once it has successfully cleared your cache and cookies.

The above procedure for clearing cache and cookies should work for the majority of websites, but certain website and applications such as WiscMail require a more thorough procedure. If you are still having issues, try to steps below.

<span>Note: The F12 developer tools in Internet Explorer 11 do not include a cache menu. This process will only work for IE10 or lower.</span>

1.Close out of Internet Options. Click on Tools and select Developer Tools.






2.In the Developer Tools window, click on Cache and select <span>Clear Browser Cache...
3.</span>
Click Yes to confirm the clearing of the browser cache





8 0
3 years ago
2. 25 POINTS!!!!!!!!!
Juli2301 [7.4K]

Answer:

D we all have responsibilities

8 0
3 years ago
Read 2 more answers
Other questions:
  • You decide to buy some stocks for a certain price and then sell them at another price. Write a program that determines whether o
    9·1 answer
  • Help 25 points!!!!!!!
    13·2 answers
  • A very simple device that connects network components and sends packets of data to all other connected devices is called a _____
    5·1 answer
  • Given the following business scenario, create a Crow's Foot ERD using a specialization hierarchy if appropriate. Granite Sales C
    12·1 answer
  • Provide a brief, high-level description of how the Internet’s connection-oriented service provides reliable transport.
    14·1 answer
  • Media messages are communicated through which of the following:
    8·2 answers
  • Why is it a good idea to leave an interview being courteous and polite?
    10·1 answer
  • Give a real life of an if statement
    13·1 answer
  • Essay about evolution of media shaped the values and norms of the society
    11·1 answer
  • What is the basic process of programming?
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!