Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Part III: Scope of Variables ( 7 Points ) The Java language defines eight basic types that are called the primitive types. These types are

Part III: Scope of Variables (7 Points)
The Java language defines eight basic types that are called the primitive types. These types are not defined
by classes and, therefore, variables of these types are not objects. These types are the necessary building
blocks for all programs and represent numbers, both integers and floating - point types, single characters
and the boolean values true and false.
Date Members
1. Data members are declared inside the class and outside of any method.
2. Data members are constants if they are modified by final, and variables, otherwise.
3. If a data member is modified by static, it belongs to the class. There is only one version of a class data
member and it is shared by all objects of this type.
4. If a data member is not modified by static, it is an instance data member. Each object of this type
has its own version of an instance data member.
5. Data members are modified by access modifiers. So far we have used the public and private access
modifiers. Additional access modifiers are protected and to use no modifier. These modifiers determine
which outside classes have access to the data members. A complete explanation of this topic will be
given at the end of this course or the beginning of the next course.
6. All data members, class or instance data, may be accessed in any instance method defined in the class.
Class methods, those that are modified by static, may only access class data members. This makes
sense, since class methods can be invoked on the class rather than on an object.
Local Variables
1. Local variables are declared inside methods and include a methods formal parameters.
2. A formal parameter of a method is known throughout the body of the method.
3. A local variable declared inside the body of a method is known from the point at which it is declared
to the end of the block in which it is declared.
4. Local variables are never modified by the access modifiers since they may only be accessed in the
method. They also are never modified by static.
Program
A class defines a data type. The code below defines a data type called Scope . This is used for illus-
tration purposes only, the actual purpose of this class is immaterial. Read the code for understanding
and then answer the questions that follow.
pub l ic c l a s s Scope {
pr ivate s t a t i c in t one =1 ;
pr ivate in t two ;
pub l ic in t t h r e e ;
pub l ic s t a t i c f i n a l in t FOUR =4 ;
pub l ic Scope ( in t w , in t x )
{
//++ i s th e autoin c r em en t o p e r a t o r and adds one onto th e v a l u e
one++;
two = w ;
t h r e e = x ;
}
pub l ic void change ( in t x )
{
in t y = one + x ;
two = one y ;
6
t h r e e = t h r e e FOUR;
}
pub l ic S t r i n g t o S t r i n g ()
{
return ( one =+ one + two =+ two + t h r e e =+ t h r e e ) ;

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

Beginning Apache Cassandra Development

Authors: Vivek Mishra

1st Edition

1484201426, 9781484201428

More Books

Students also viewed these Databases questions

Question

Provide examples of Dimensional Tables.

Answered: 1 week ago