Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

An integer will be passed to your method. Take that value and add a constant to it . That constant is available within the class,

An integer will be passed to your method. Take that value and add a constant to it. That constant is available within the class, to all methods found inside the class.
This is important because this provides a way of providing the same values to multiple methods used by objects based on a particular class. Furthermore, if that constant is found to be private (private keyword), then it's only available within the class (or object) and is not directly accessible outside.
In this case, the class-wide constant (final keyword) has a value of 100. Modify the method to permit that value to be added to whatever value is passed to your method.
So, if -1 is passed to your method, your method should output 99(i.e.-1+100).
In this activity you will see variables like this:
private static final int MY_VALUE =56;
This is a constant (keyword final) integer called MY_VALUE that can be used in a global context, within the class and between objects that share the same class (keyword static). Because it is private, MY_VALUE cannot be directly accessed from outside the class or an object created from the class.
This touches on the concept of scope. Variables created in one location of your program may not be accessible outside of that location. The scope (LinkedIn Learning link) limits where you can use variables.
In summary, these keywords are important:
private: the value can't be seen or used outside the class or object.
static: the value is global (across multiple methods) inside the class or object.
final: the value is not a variable. It won't change. Basically, a constant.An integer will be passed to your method. Take that value and add a constant to it. That constant is available within the class, to all methods found inside the class.
This is important because this provides a way of providing the same values to multiple methods used by objects based on a particular class. Furthermore, if that constant is found to be private (private keyword), then it's only available within the class (or object) and is not directly accessible outside.
In this case, the class-wide constant (final keyword) has a value of 100. Modify the method to permit that value to be added to whatever value is passed to your method.
So, if -1 is passed to your method, your method should output 99(i.e.-1+100).
In this activity you will see variables like this:
private static final int MY_VALUE =56;
This is a constant (keyword final) integer called MY_VALUE that can be used in a global context, within the class and between objects that share the same class (keyword static). Because it is private, MY_VALUE cannot be directly accessed from outside the class or an object created from the class.
This touches on the concept of scope. Variables created in one location of your program may not be accessible outside of that location. The scope (LinkedIn Learning link) limits where you can use variables.
In summary, these keywords are important:
private: the value can't be seen or used outside the class or object.
static: the value is global (across multiple methods) inside the class or object.
final: the value is not a variable. It won't change. Basically, a constant.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle Database Foundations Technology Fundamentals For IT Success

Authors: Bob Bryla

1st Edition

0782143725, 9780782143720

Students also viewed these Databases questions