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
Svetradugi [14.3K]
4 years ago
5

Write a class definition of a class named 'Value' with the following: a constructor accepting a single integer parameter a const

ructor with no parameters a method 'setVal' that accepts a single parameter, a boolean method, 'wasModified' that returns true if setVal was ever called for the object. a method 'getVal' that returns an integer value as follows: if setVal has ever been called, it getVal returns the last value passed to setVal. Otherwise if the "single int parameter" constructor was used to create the object, getVal returns the value passed to that constructor. Otherwise getVal returns 0.
Computers and Technology
1 answer:
Amanda [17]4 years ago
7 0

Answer:

The answer to this question can be given as:

Class definition:

public class Value  //define class.

{

private boolean modified = false;   //define the boolean variable and assign value.

private int y;   // define integer variable.

public Value(int x)  //define parameterized constructor

{

y = x;  //holding value in variable y.

}

public Value()  //define default constructor.

{

}

public int getVal()  //define function getVal.

{

return y;  //return value.  

}

public void setVal(int x) //define function setVal.

{

y = x;  //hold parameter value.  

modified = true;   .//hold boolean value.

}

public boolean wasModified() //define function wasModified.  

{

return modified;   //return value.

}

}

Explanation:

In the above class definition firstly we define a class that is "Value". In this class we constructor,methods and variables that can be described as:

  • In the class we define a variable that is modified and y both variable is private but the modified variable is boolean type that is used for hold only true or false value and variable y is an integer variable.
  • Then we define constructors. In this class, we define parameterized constructor and default constructor. In the default constructor, we do write anything but in the parameterized constructor we use the private variable y for the hold parameter value.
  • Then we define a function getVal() and setVal(). The getVal() function is used to return private variable (y) value and setVal() function is used to set the value of y. and we also change the modified variable value that is "True".
  • At the last we define a wasModified() function. In this function, we return the modified variable value.
You might be interested in
What is output?
Misha Larkins [42]

Answer:

The output of code will be 10

Explanation:

We need to find output of following code:

C = 1

Sum = 0

while (c less than 10):

C = c + 3

sum = sum + c

print (sum)

Solution:

We will check the condition of while loop, if the condition is true, then the statements inside the loop will be executed. Since brackets are not available so, only one statement is linked with while loop.

First while loop will be executed c < 10 (1<10) the condition becomes true, and statement c=c+3 will be executed ( 4=1+3) and then loop condition will be checked (4<10) the condition becomes true, and statement c=c+3 will be executed ( 7=4+3) and then loop condition will be checked (7<10) the condition becomes true and statement c=c+3 will be executed ( 10=7+3) and then loop condition will be checked (10<10) the condition becomes false, so we will come outside loop body and execute: sum=sum+c (10=0+10) and print sum i. e 10

So, The output of code will be 10

6 0
3 years ago
Digital art is created by using
enyata [817]

Answer:

D. Computers

Explanation:

Digital art is when you make art on electronic devices.

8 0
3 years ago
What is communication ?? ​
maksim [4K]

Answer:

Communication is the act of giving, receiving, and sharing information

3 0
2 years ago
Read 2 more answers
Did the first generation of computers use microprocessors.
Katena32 [7]

no they used standard 8088 Intel processors

hope this helps

8 0
2 years ago
Read 2 more answers
What part of the interface displays the external references contained in a selected cell? the status bar the Review tab the scro
gulaghasi [49]

The formula bar

In Excel, external references reference a cell or a range of cells in another workbook. The formula of an external reference result can be displayed in a formula bar. A formula bar displays the value or formula entered in an active cell. It displays information being entered as you type in the active or current cell. Contents of an external reference can also be edited in the formula bar.

4 0
3 years ago
Other questions:
  • Whatis meant by Translation Lookaside Buffer?
    5·1 answer
  • URGENT!! You decide not to use any recipes or information from the "Don't Be an Animal Murderer" Web site. What characteristic o
    7·2 answers
  • Write the definitions of two classes Day and Night. Both classes have no constructors, methods or instance variables. Note: For
    8·1 answer
  • When would it be easier to use Cut and Paste over Drag and Drop? Explain?
    6·1 answer
  • A website requires their users to create a password for their own account using numbers from 0-5, inclusive, non-repeatedly. The
    7·2 answers
  • Which term describes the gallery that allows you to customize and format text as a graphic? Pull Quote Text Box WordArt Drop Cap
    13·2 answers
  • Which entity might hire a Computer Systems Analyst to help it catch criminals?
    12·2 answers
  • Consider a computer that uses 5 bits to represent positive integers and uses all 5 bits to represent the value.
    9·1 answer
  • What’s the difference between var and val?
    9·1 answer
  • Why might you use the More button in the Find and Replace dialog box?
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!