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
Does the Main Content (MC) of a web page include searchboxes?
Tanzania [10]
Yes it does use search boxes
8 0
3 years ago
Read 2 more answers
Which of the following are characteristics of a good webmail message select all that apply
emmainna [20.7K]

add choices please :)


6 0
2 years ago
How to enhance the video to full screen in filmora
Anastaziya [24]

Answer:

The answer to your question is to click on the button with the square on the window options ribbon.

6 0
2 years ago
Sharon is a network engineer for your firm and is investigating the WAN connection into the hot site. In the event of operations
lisabon 2012 [21]

Answer:

The correct answer to the following question will be "Peak capacity" and "Bandwidth starvation".

Explanation:

Peak capacity has been used to characterize the gradient aqueous phase separation efficiency or performance. It represents the overall conceptual number of operations or components which can be isolated consistently with something like a given set of analytical circumstances and column with

⇒ Rs =1 (Figure 1 and Equation 1)

Certain traffic competing at its policies for the available or unused bandwidth will theoretically enable classes with lower value rates to starve to bandwidth.

Due to these activities, Sharon is concerned about "Bandwidth starvation" and "Peak capacity".

8 0
3 years ago
Where does an MPLS label go in a PDU?
Natalija [7]

Answer: Between Layers 2 and 3

Explanation:

In between Layer 2 and Layer 3 the MPLS header is present and is known as Shim header. It is also said to be in 2.5.

6 0
2 years ago
Other questions:
  • Modern database tools support ________________, which entails separating data from the programs that manipulate data.
    14·1 answer
  • Generally speaking, mobile sites are good for acquiring new customers and inspiring new relationships while mobile apps are good
    6·1 answer
  • Regarding the Internet of Things (IoT), a business involved in utilities, critical infrastructure, or environmental services can
    10·1 answer
  • An option button is a square button that enables you to make one choice among two or more options.
    15·1 answer
  • Which protocol is used by the client for microsoft networks and file and printer sharing for microsoft networks to communicate w
    10·1 answer
  • Analyst is investigating proxy logs and found out that one of the internal user visited website storing suspicious java scripts.
    8·1 answer
  • ​if a primary key combines two or more fields, then it is called a _____.
    14·1 answer
  • Among the eight unique features of​ e-commerce, which is related to the ability to interact with web technology​ everywhere?
    14·1 answer
  • what is the purpose of the Outline view in word 2016? check all that apply. 1. editing the format of size and text. 2.working wi
    11·1 answer
  • What is the optimal number of members for an Agile team?
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!