Question

In: Computer Science

I'm doing a practice test and I can't seem to find the answers anywhere for these...

I'm doing a practice test and I can't seem to find the answers anywhere for these specific questions. If someone could please help clarify so I can learn that would be helpful!

1. Identify the true statements. Select ALL that apply.


a. Setters and getters are not required for public instance variables.

b. A setter method is return-type void and takes a parameter of the same type as its field.

c. A getter method has the same return-type as the field it retrieves and takes no parameters.

d. Every private instance variable in a class definition must have a mutator method.

2.
private char gender;public class Person {

static int number;

//...

public static void main(String[] args) {

Person person;

   //...

}

public static void callPerson(int hours) {

double payRate = 24.99;

}

}

The code above compiles okay. Refer to it to complete this matching exercise.

_____

person

_____

hours

_____

number

_____

payRate

_____

gender

1.

local reference variable

2.

class variable

3.

instance variable

4.

parameter

5.

local primitive variable


3. Identify the true statements. Select ALL that apply.

a. Static methods are also class methods

b. Static methods of a class can be called without instantiating the class.

c. A static method cannot access the data members of its own class.

d. A non-static method can be called from a static method.

4. What does the public visibility modifier mean?

a. means accessible from any class in the same package.

b. means accessible to the current program.

c. means accessible to any method in the class.

d. means accessible from any other classes.

5.

3. public class Person {
4. private double salary;
5. public Person() {
6. salary = 1000.0;
7. }

What type of constructor is illustrated by lines 5 through 7?


6. Identify the true statements. Select ALL that apply.

a. Constants in a class should be declared as final static.

b. Static variables and static methods of a class can be accessed by an object of that class and by the class name.

c. Static variables have a default value of null.

d. Anonymous objects are possible in Java.


7. What Java keyword sometimes used in a class definition refers to the class itself?

Solutions

Expert Solution

1.

a.Public instance variable can be accessed(used) from outside the class. Hence setter and getter methods are not required. Thus the statement is true.

b. Setter method as the name suggest, it sets a value to a variable. Hence the return value is void and the parameter should be same as variable type to which this parameter value is assigned. Hence this statement is true.

c. Getter method is to get the value of the field, hence its return type should be of same type of field. As it is just getting the value, no parameters are required. Thus this statement is true.

d. Private instance variable can't be accessed from outside the class. Hence there should be an interface to access this variable either to assign a value or retrieve its value. This interface is nothing but mutator method. Thus this statement is true.

2. Match:

person: instance variable

hours: parameter

number: class variable

payRate: local primitive variable( allocated in stack and scope is till it's function(function in which it is declared) execution end

gender: local reference variable(allocated in heap and this variable point to that object).

2. a. Static methods are class methods as they belong to class and not to object of class. Hence it is true.

b. Static methods can be called without instantiating the class. Hence this statement is true.

c. Static methods can access data members that are too static(static variable) which belongs to the same class. Hence this statement is not true.

d. Static methods can't call non-static methods. It can call only other static methods of its own class. Hence this statement is not true.

4. Public access modifier makes irrespective of code location, it can access class, methods, variable which are assigned to public modifier. Hence the entire program can access them. Correct option is: b


Related Solutions

This isn't a homework but since I can't seem to find any answers for it, I...
This isn't a homework but since I can't seem to find any answers for it, I would like to receive some insights from you experts! So, I heard that UK has official left the European Union on Jan 31st (aka Brexit). Are there any trade deals that have been signed? or any negotiations that has been reached? please provide me with some updates I can't seem to find any info on which trade deals were signed and etc. thanks! p.s...
Practice problems in my statistics textbook I can't find answers for to verify mine: A regular...
Practice problems in my statistics textbook I can't find answers for to verify mine: A regular six-faced fair die will be rolled. Let Y be the number obtained. a.) What is the expected value of Y? b.) What is the variance of Y?
In java, I keep getting the error below and I can't figure out what i'm doing...
In java, I keep getting the error below and I can't figure out what i'm doing wrong. Any help would be appreciated. 207: error: not a statement allocationMatrix[i][j];
Macroeconomics class What is an identity? Explain them and all components. I can't find this anywhere...
Macroeconomics class What is an identity? Explain them and all components. I can't find this anywhere...
How can I write an essay about Endoscopies with an bibliography? I can't seem to find...
How can I write an essay about Endoscopies with an bibliography? I can't seem to find an example. I need a step by step guide. Who can help me write it please and Thank you
Can't seem to find the answer to these questions... this is a two part question and...
Can't seem to find the answer to these questions... this is a two part question and would love an explanation for both. Thanks in advance! The ductus arteriosus and the ductus venosus are two key vessels in the fetal circulation that are absent in the adult circulation. What are their functions in the fetus? Why are they necessary? At birth, the fetal circulation is transformed instantaneously into the adult circulation with practically no transition. How is this marvelous process possible?
I need to draw a cylinder in java with user input, and I can't seem to...
I need to draw a cylinder in java with user input, and I can't seem to get my lines to line up with my ovals correctly from the users input... I know I will have to either add or subtract part of the radius or height but I'm just not getting it right, here is how I'm looking to do it.            g.drawOval(80, 110, radius, height);            g.drawLine(?, ?, ?, ?); g.drawLine(?, ?, ?, ?);   ...
Hi there, I am having a bit of an issue that I just can't seem to...
Hi there, I am having a bit of an issue that I just can't seem to figure it out. My code is supposed to read from another file and then have an output of a number for each categorie ////////Required Output/////// Movies in Silent Era: 0\n Movies in Pre-Golden Era: 7\n Movies in Golden Era: 581\n Movies in Change Era: 3445\n Movies in Modern Era: 10165\n Movies in New Millennium Era: 15457\n My program is: import java.util.ArrayList; public class MovieReducerEraCount...
i'm doing this practice problem and i'm really struggling. if you be so kind to complete...
i'm doing this practice problem and i'm really struggling. if you be so kind to complete so it can help me comprehend. Please be sure to include a visual of the coordinate plane for questions 1 & 3. Thank you. 1)A pipe needs to run from a water main, tangent to a circular fish pond. On a coordinate plane, construct the circular fish pond at a given location and specify your center point and radius. 2)Write your circular fish pond...
I'm doing this homework on relativity and I'm not very good at it. :( I keep...
I'm doing this homework on relativity and I'm not very good at it. :( I keep getting things wrong or confused in my head. Please help me to understand this! Thank you in advance! 3. Person A is at rest with a light clock. Person B is in a car moving to the left (as seen by Person A with a light clock). Discuss how each person will perceive time. Use algebra to find the time measured by Person A...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT