What is the significance of using the access modifier

Assignment Help Basic Computer Science
Reference no: EM13858269

1. Which is the correct syntax for a mutator method?

a. public int getWeight() { return this.weight; }
b. public boolean isDeclawed() { return this.declawed; }
c. public void getWeight() { return this.weight; }
d. public void setWeight(double weight) { this.weight = weight; }

2. Which statement shows the correct way to declare and initialize a named constant that represents absolute zero?
a. final int absoluteZero = -273.15;
b. final double absoluteZero = -273.15;
c. final int ABSOLUTE_ZERO = -273.15;
d. final double ABSOLUTE_ZERO = -273.15;

3. In the following class: public class Height { private double height; private String unitsOfMeasurement; //************************ public Height()
{ this.unitsOfMeasurement = "in"; }
public void setHeight(double height)
{ this.height = height; this.unitsOfMeasurement = "cm"; }
public void setHeight(double height, String unitsOfMeasurement) { this.height = height; this.unitsOfMeasurement = unitsOfMeasurement; }
public void print() { System.out.println(this.height + " " + this.unitsOfMeasurement); } } // end class Height

Which method is the constructor?
The print method
The Height method
The setHeight method
This class does not implement a constructor.

4. Java primitive types include _________.
integer, double, string, boolean, long and float
integer, double, float, array, boolean and long
long, integer, string, array, float, double and character
long, double, character, float, integer and boolean

5. What is the name for the circled items in the following statement?
What is the name for the circled items in the following statement?

modulus specifier
format specifier
flags specifier
precision specifier

6. Which Java operator is used for concatenation?
&&
+
.
||

7. Given the following code fragment (presume there is a class called Car implemented):
Car mazdaCar = new Car();
Car subaruCar = new Car();
mazdaCar.setYear(2008);
mazdaCar.setColor(black);
subaruCar = mazdaCar;
subaruCar.setYear(2011);
mazdaCar.printYear();

What will display on the screen for mazdaCars year when mazdaCar executes printYear()?
a. 2008
b. 2010
c. 2011
d. Black

9. Given the following method from a class: public double calculateArea(double length, double width) { double area; area = length * width; return area; }
What is the scope of the variables length and width?
a. Global to the class.
b. Local to the method.
c. Global to all objects created from the class.
d. None of the above.

10. In the following code fragment:
5 Person person1 = new Person();
6 Person person2 = new Person();
7 8 person1.setName("Bugs Bunny");
9 person2.setName("Daffy Duck");
10 System.out.println(person1.getName() + ", " + person2.getName()); 11 12 person1.swapPerson(person2); 13 System.out.println(person1.getName() + ", " + person2.getName());
What is being passed to the swapPerson method in line 12:
a. an object
b. an object reference
c. a class
d. a class reference

11. In the following Java code fragment:
int postion1 = 15;
int postion2 = 18;
int distanceApart = Math.abs(position1 - position2);
What type of method is the Math.abs() method?
a. Instance method
b. Class method
c. Final method
d. Inherited method

12. When a public method needs to access both class members (variables and methods) and instance members (variables and methods), the method must be a / an _________ method.
a. instance
b. helper
c. class
d. None of the above.

13. In the following class:
public class Height { private double height; private String unitsOfMeasurement;
public Height() { this.unitsOfMeasurement = "in"; }
public void setHeight(double height) { this.height = height; this.unitsOfMeasurement = "cm"; }
public void setHeight(double height, String unitsOfMeasurement) { this.height = height; this.unitsOfMeasurement = unitsOfMeasurement; }
public void print() { System.out.println(this.height + " " + this.unitsOfMeasurement); } } // end class Height Which method is overloaded?
a. The print method
b. The Height method
c. The setHeight method
c. None of the methods are overloaded.

14. What must a method return if the method implements method call chaining?
The calling object
A class variable
The class
Null

15.

Which code segment is representative of a properly formatted nested loop?
a. while(i<5) { }
b. while(j<3) { } do { while(j<3) { } }
c. while(i<5); do { while(j<3) { } }
d. while(i<5) while(i<5) { while(j<3) { }do; }

no answer matches

16. What is the fundamental difference between a do loop and a while loop?
a. Code inside a do loop will never be executed.
b. Code inside a while loop is guaranteed to execute at least once.
c. Code inside a do loop is guaranteed to execute at least once.
d. Do loops and while loops are the same.

17. What is the meaning of the java statement: import java.util.Scanner;?
a. It tells the java compiler to include the Scanner class from the utility package.
b. It tells the java compiler to exclude only the Scanner class from the compile process.
c. It signals the java compiler to scan the source code for errors.
d. None of the above.

18. Given the following code fragment: double interestRate = 0.05; double balance = 100.5; int interestInDollars = (int)(interestRate * balance); System.out.println(interestInDollars);

What value will display on the screen?
a. 5
b. 5.025
c. 5.03
d. 0

19. What is the significance of using the access modifier private with instance variables?
a. It makes instance variables easier to access from outside the object.
b. Using private provides data encapsulation.
c. It makes the variables inaccessible from within the object.
d. The private access modifier should never be used.

20. Given the following code fragment: System.out.println("\"Four score and seven years ago\"");
What will display on the screen?
a. Four score and seven years ago
b. Four score and seven years ago
c. \Four score and seven years ago\
d. "\"Four score and seven years ago\""

It will display:
"Four score and seven years ago"
Match your answer accordingly



21. Given the following, which is the correct file name and extension to use when saving the file?
public class SomeJavaClass { public static void main(String[] args) { System.out.print(Java is ?); }//end main }//end someJavaClass
a. someJavaClass.txt
b. SomeJavaClass.txt
c. someJavaClass.java
d. SomeJavaClass.java

22. In the context of OOP, objects __________.
a. do not encapsulate
b. data persist forever after being instantiated
c. contain only accessor methods
d. have state and behavior


23. Given the following code fragment. (presume there is a Hat class with a constructor that requires the hat type, price and color as arguments and there is a accessor method called getPrice that returns the price):
a. Hat hat1 = new Hat(baseball, 5.21, blue); int quantityToOrder = 0; double totalPrice = 0.0; Scanner userInput = new Scanner(System.in); System.out.print(How many hats to order?); quantityToOrder = Integer.parseInt(userInput.nextLine()); totalPrice = (hat1.getPrice() * quantityToOrder); System.out.println(Order Total = $ + totalPrice);
What will display on the screen when the user orders 4 hats?

a. Order Total = $20.84
b. Order Total = $20
c. Order Total = $5.21
d. Order Total = $5

24. In the following Java code fragment: public class SomeClass { private static int someVariable; }//end SomeClass
What is the significance of the keyword static?
It makes the variable someVariable an instance variable
b. It makes the variable someVariable a class variable
c. It makes the variable someVariable a local method variable
d. None of the above

25. Given the following code fragment: String name = "Joseph Cool"; System.out.println(name.charAt(5));
What will display on the screen?
a. h
b. p
c. 5
d. e

26. Instance methods ___________.
a. specify the object attributes (data)
b. can be used without creating an object
c. specify the object behaviors
d. must contain the static keyword in their definition

27. Given the following code fragment:
int operand1 = 4;
int operand2 = 3; double result = operand1 / operand2;
System.out.println(result);

What is displayed on the screen?
a. 0
b. 1.0
c. 1.3333333333333333
d. 1

28. Given the following code fragment:
boolean logicValueA = true;
boolean logicValueB = true;
System.out.println("Boolean Result: " + (logicValueA && logicValueB));
What will display on the screen?
a. Boolean Result: false
b. Boolean Result: true
c. Boolean Result: and
d. Boolean Result: or

29. A class specifically written to use other classes in its main method is called a _________.
a. driven class
b. static class
c. driver class
d. main class

30. Given the following code fragment:
boolean logicValueA = true;
boolean logicValueB = false;
System.out.println("Boolean Result: " + (!logicValueA || logicValueB));

What will display on the screen?
a.Boolean Result: false
b. Boolean Result: true
c. Boolean Result: and
d. Boolean Result: or

31. What is the term for the lower and upper case pattern that must be used for variable and method identifiers?
a. straight case
b. alternating case
c. camel case
d. None of the above.

32. Given the following code fragment:
int x = 5;
int y = 8;
int z = 0;
while(y < 20) { z = x + y; x = y; y = z; System.out.println(y); }
if(y > 22) { System.out.println(z); }
else if(y < 22) { System.out.println(x); }

What will display on the screen?
a. 13 21 13
b. 13 21 21
c.13 25 13
d.13 28 28

33. Which statement shows the correct way to define a method that does not provide a return value?
a. public void displayFraction(int numerator, int denominator) { }
b.public int displayFraction(int numerator, int denominator) { }
c.public Fraction displayFraction(int numerator, int denominator) { }
d.public null displayFraction(int numerator, int denominator) {

Reference no: EM13858269

Questions Cloud

Demonstrate the plan for testing : Use internal, external, and anchor links in the application or site. Demonstrate the plan for testing
Identify the implications for future competitiveness : Conduct a brief, well-argued analysis of the past 5 to 10 years of strategic innovation actions by your selected company - which explains the evolution of the company through the lenses of both traditional and blue ocean innovative strategy framew..
Calculate the value of an american put option : Q1.  Use DerivaGem to calculate the value of an American put option on a non-dividend-paying stock when the stock price is USD 30, the strike price is USD 32, the risk-free rate is 5%, the volatility is 30% and the time to maturity is 1.5 years. (..
Contrast available it security solutions to address : Analyze the security challenges arising from adding e-commerce to the website
What is the significance of using the access modifier : What is the significance of using the access modifier private with instance variables?
Explain the use of substances : What explanation can psychology give to explain the use of substances? Be sure to include the media influences that are represented in your poster (e.g., advertisements for the drug, or PSA clips against the drug) as well as information presented ..
Evaluate strategic approaches to innovation on performance : While the framework that Kim and Mauborgne (2004) outline may seem simple to understand, it is very difficult to implement. In part, it is very difficult for companies to do new things, or to do things in new ways, because inertia is real in all o..
Provide specific mitigation strategies : Provide specific mitigation strategies for any issues that could detract from the project
What treatments might be effective in treating it : What symptoms should her family/doctor look for that she has developed an eating disorder? If she develops this eating disorder, what treatments might be effective in treating it

Reviews

Write a Review

Basic Computer Science Questions & Answers

  Write function xsort takes list strings returns sorted list

Write the function Xsort wich takes in a list of strings and returns sorted list with all words beginning wih "X" first in the list. f.ex: xsort (['kex', 'xylofonn', 'epli', 'xenos', 'asni']) returns ['xenos', 'xylofonn', 'asni', 'epli', 'kex']

  Depreciation on equipment

Prepare adjusting entries for the following transactions. Omit explanations. 1. Depreciation on equipment is $800 for the accounting period.2.There was no beginning balance of supplies and purchased $600 of office supplies during the period. At the ..

  Cpu training

What kinds of tools would be considered media for computer-based training?

  How do you print the rightmost element in a binary tree

How do you print the rightmost element in a binary tree?

  Explain potential challenge of collaboration of firms

Author suggests ways to do this. Explain the potential challenge that this kind of collaboration might face and explain the way of dealing with it.

  Prepare the case budget for the fourth quarter

Using a spreadsheet to prepare the case budget for the fourth quarter. The cash budget should be included as an appendix to the written report and should be referenced in the written report.

  Design a spreadsheet to understand required funds

Using the parameters in (a), construct a graph showing how the amount required for the order would vary if the unit cost of a package of bandages rose by $0.25, $0.50, and so on, up to $3.00 per package.

  Using the assigned journal article for the week compose a

using the assigned journal article for the week compose a two page paper on the unified modeling language uml. what is

  Java game development jump it

The game "Jump It" consists of a board with n positive integers in a row, except for the first column, which always contains zero. These numbers represent the cost to enter each column. Here is a sample game board with n set to 6:

  Write a program to input an double array

Write a program to input an double array, and then computes some simple statistics on that array. The program should have two user-defined methods to help you with the task.

  Define implementing streaming media within the organization

What are two site examples that have images or multimedia that are used effectively on the site? Why do you think they work well on the site? Include the URLs of the sites in your response for others to view your selections.

  Intentional and unintentional plagiarism

What is the difference between intentional and unintentional plagiarism

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd