Written by students who passed Immediately available after payment Read online or as PDF Wrong document? Swap it for free 4.6 TrustPilot
logo-home
Exam (elaborations)

The - indicates a class' private item. True False - answer true The + indicates additional private items. True False - answer false In addNumYears(), which line adds the parameter numYears to the existing value of field numYears? this.numY

Rating
-
Sold
-
Pages
12
Grade
A+
Uploaded on
22-09-2024
Written in
2024/2025

The - indicates a class' private item. True False - answer true The + indicates additional private items. True False - answer false In addNumYears(), which line adds the parameter numYears to the existing value of field numYears? Years = Years + numYears; Years = numYears + numYears; numYears = Years + numYears; - answer a In addNumYears(), which line assigns the field numYears with 0? numYears = 0; this(numYears) = 0; Years = 0; - answer c In addNumYears(), which line assigns the field numYears with the parameter numYears? numYears = Years; Years = numYears; - answer b Long id = 12398L; Autoboxing Unboxing Both - answer a Boolean lowStock = itemCount 10; Autoboxing Unboxing Both - answer a Assume newRate is a double and adjustRate is a Double. newRate *= adjustRate; Autoboxing Unboxing Both - answer b Assume newTime is a double, and totalTime is a Double. totalTime = totalTime + newTime; Autoboxing Unboxing Both - answer c Assume the calcResult() method returns an Integer and has the signature calcResult(Integer num1, Integer num2), and that variables xVal and yVal are of type int. Integer zVal = calcResult(xVal, yVal); Autoboxing Unboxing Both - answer a API is short for ___. Authoring Program Instructions Applied Programming Implementation Application Programming Interface Automated Program Instructions - answer c What is the blueWidget's inStock at the end of main( )? public class Widget { private int inStock; public Widget() { inStock = 10; } public void addInventory(int amt) { inStock = inStock + amt; } public static void main(String [] args){ Widget blueWidget = new Widget(); Widget greenWidget = new Widget(); blueWInventory(15); greenWInventory(5); } } } 25 10 30 15 - answer a Which is true? Integer cost = 15; int quantity = 20; quantity is a reference variable cost stores the value 15 cost stores an object location Variables cost and quantity store memory locations - answer c Which is true? A testbench should only print messages when a test case fails Calling every method once ensures 100% code coverage A testbench should test all possible values Passing all test cases ensures a program is bug free - answer a How many references are declared? Dog labrador = new Dog(); Dog poodle; Dog beagle = new Dog(); poodle = beagle; poodle = labrador; 4 2 3 Error: Illegal assignment statement - answer 3 Given a programmer-defined class called Person, what is output? Person barb = new Person(18); Person jessie = new Person(21); change(barb, jessie); Sln(Age()); public static void change(Person p1, Person p2){ p1 = p2; } Error: null pointer exception 21 The memory location of barb 18 - answer 18 Which comparison should not be used? Integer score1 = 20; Integer score2 = 30; int score3 = 40; score1 == score2 score2 == score3 score1 = score3 score1 score2 - answer a What is stored in score1, score2, and grade? Integer score1 = 72; int score2 = 85; Character grade = 'C'; obj reference, 85, obj reference 72, 85, C obj reference, obj reference, C obj reference, obj reference, obj reference - answer a Which package contains the Scanner class? - answer a What is the value of fordFusion's odometer at the end of main( )? public class SimpleCar { private int odometer; public SimpleCar() { odometer = 0; } public SimpleCar(int miles) { odometer = miles; } public void drive(int miles) { odometer = odometer + miles; } public static void main(String[] args) { SimpleCar fordFusion = new SimpleCar(); SimpleCar hondaAccord = new SimpleCar(30); fordF(100); fordF(20); } } 30 100 120 20 - answer c The keyword ________ is required to declare a class. class All of the answers. private public - answer a What is the greenWidget's inStock at the end of main( )? public class Widget { private int inStock; public Widget() { inStock = 10; } public void addInventory(int amt) { inStock = inStock + amt; } public static void main(String [] args){ Widget greenWidget = new Widget(); greenWInventory(15); greenWInventory(5); } } } 30 5 20 10 - answer a Which replaces "Apples" with "Bananas"? ArrayListString groceryList; groceryList = new ArrayListString(); groceryL("Bread"); groceryL("Apples"); groceryL("Grape Jelly"); groceryL(2, "Bananas"); groceryLce("Apples", "Bananas"); groceryLce(1, "Bananas"); groceryL(1, "Bananas"); - answer d If myClass has a constructor with a parameter of type String, select the other constructor that should be included. public myClass( ) {. . .} public myClass(String str1, String str2) {. . .} public myClass(int value ) {. . .} public void myClass( ) {. . .} - answer a You should add the static keyword in the place of ? in Line ________ in the following code: 1 public class Test { 2 private int age; 3 4 public ? int square(int n) { 5 return n * n; 6 } 7 8 public ? int getAge() { 9 } 10 } in line 4 in both line 4 and line 8 none in line 8 - answer a Analyze the following code: public class Test { private int t; public static void main(String[] args) { int x; Sln(t); } } The variable t is not initialized and therefore causes errors. The program compiles and runs fine. The variable x is not initialized and therefore causes errors. The variable t is private and therefore cannot be accessed in the main method. t is non-static and it cannot be referenced in a static context in the main method. - answer e Which is true? Javadoc comments should be placed directly after a class definition. Javadoc documentation is intended for users of a class. Private class member comments are automatically included by the Javadoc tool. @author tags are required by the Javadoc tool. - answer b What is output? ArrayListInteger numList = new ArrayListInteger(); int count; for(count = 1; count 10; ++count) { numL(count); } Sln(numL(4)); 4 Error: index out of bounds 5 6 - answer 5 Which XXX adds a student to the ArrayList? public class Roster { private ArrayListStudent studentList; public void addStudent(Student s){ XXX; } } studentL(s); add(s); studentList = s; addStudent(s) - answer a Creating an independent class that has the same members as an existing class creates duplicate code. true false - answer true Creating a derived class is generally less work than creating an independent class. True False - answer true User-defined classes are not derived from the Object class. True False - answer false All classes can access Object's public and protected methods like toString() and equals(), even if the methods are not explicitly overridden. True False - answer true The built-in Integer class overrides the toString() method in order to return a String representing an Integer's value. True False - answer true The Object class's toString() method returns a String containing only the Object instance's type. True False - answer false An item of any class type may be added to an ArrayList of type ArrayListObject. Yes No - answer yes [The Object class is the base class for all classes. Thus, an item of any class type is implicitly casted to the Object type and added to the ArrayList.] Consider a program that catalogs the types of trees in a forest. Each tree object contains the tree's species type, age, and location. This program will benefit from an abstract class to represent the trees. True False - answer false [No information exists that is specific to each species of tree. So each tree object can simply possess the species type, age, and location information.] Consider a program that catalogs the types of trees in a forest. Each tree object contains the tree's species type, age, location, and estimated size based on age. Each species uses a different formula to estimate size based on age. This program will benefit from an abstract class. True False - answer true [A superclass Tree might store the age and location, and specify an estimateSize() behavior. Subclasses for each species like OakTree then implements the species particular growth rate formula.] Consider a program that maintains a grocery list. Each item, like eggs, has an associated price and weight. Each item belongs to a category like produce, meat, or cereal, where each category has additional features, such as meat having a "sell by" date. This program will benefit from an abstract class. True False - answer false [Normal inheritance is sufficient. A superclass like Item might implement price and weight. Then subclasses like MeatItem might add behavior like a "sell by" date. But no behavior was mentioned that must be implemented by all subclasses.] A UML class diagram is a behavioral diagram. True False - answer false [structural] A UML class diagram describes everything that is needed to implement a class. True False - answer false Provides only static final fields. Interface Abstract class - answer interface Provides variables/fields. Interface Abstract class - answer abstract Provides an API that must be implemented and no other code. Interface Abstract class - answer interface Consider a Dog class and a Mammal class. Which is true? The Mammal class is concrete Both classes are concrete The Mammal class is abstract The Dog class is abstract - answer c ___ refers to determining which program behavior to execute depending on data types. Inheritance Polymorphism Overloading Overriding - answer b Polymorphism means ________. that a class can contain another class that a class can extend another class that data fields should be declared private that a variable of supertype can refer to a subtype object - answer d Consider the following declaration for a class A. class A { private int x; private int y; public A(int x, int y) { this.x = x; this.y = y; } } Class B is a subclass of A. Which of the following can be constructors in B? I: public B() { } II: public B(int x, int y) { super(x, y); } III: public B() { super(0, 0); } IV: public B(int x, int y) { this.x = x; this.y = y; } I IV III II - answer III and II Inheritance means ________. that a class can extend another class that a class can contain another class that data fields should be declared private that a variable of supertype can refer to a subtype object - answer a Programmers often use a powerful programming paradigm that consists of three key features — classes, inheritance, and abstract classes. What is the paradigm called? Structured programming Object-oriented programming Modular programming Universal Modeling Language - answer b Given the following code: class C1 {} class C2 extends C1 { } class C3 extends C2 { } class C4 extends C1 {} C1 c1 = new C1(); C2 c2 = new C2(); C3 c3 = new C3(); C4 c4 = new C4(); Which of the following expressions evaluates to false? c3 instanceof C1 c2 instanceof C1 c4 instanceof C2 c1 instanceof C1 - answer c Which is true? public class Vehicle { protected String name; private int ID; } public class Car extends Vehicle { protected int miles; } Car members do not have access to any Vehicle members Car members have access to Vehicle name Car members have access to Vehicle ID Vehicle members have access to Car miles - answer b Which lines cause a compile error? public class Vehicle { protected String name; private int ID; public setID(int pID) {...} } public class Car extends Vehicle { private int miles; public Car() { 1 miles = 145; 2 setID(99); 3 ID = 47; 4 name = "Honda"; } } line 3 only lines 1 and 3 lines 3 and 4 there are no errors - answer a Which class definition requires Square to follow the API of Shape? public interface Shape public class Square extends Shape public class Square implements Shape public class Shape implements Square - answer c

Show more Read less
Institution
CSC - Cyber Secure Coder
Module
CSC - Cyber Secure Coder

Content preview

CSC 222 exam 3 Questions and Answers
The - indicates a class' private item.
True
False - answer true

The + indicates additional private items.
True
False - answer false

In addNumYears(), which line adds the parameter numYears to the existing value of
field numYears?

this.numYears = this.numYears + numYears;
this.numYears = numYears + numYears;
numYears = this.numYears + numYears; - answer a

In addNumYears(), which line assigns the field numYears with 0?

numYears = 0;
this(numYears) = 0;
this.numYears = 0; - answer c

In addNumYears(), which line assigns the field numYears with the parameter
numYears?

numYears = this.numYears;
this.numYears = numYears; - answer b

Long id = 12398L;

Autoboxing
Unboxing
Both - answer a

Boolean lowStock = itemCount < 10;
Autoboxing
Unboxing
Both - answer a

Assume newRate is a double and adjustRate is a Double.
newRate *= adjustRate;

Autoboxing

, Unboxing
Both - answer b

Assume newTime is a double, and totalTime is a Double.
totalTime = totalTime + newTime;
Autoboxing
Unboxing
Both - answer c

Assume the calcResult() method returns an Integer and has the signature
calcResult(Integer num1, Integer num2), and that variables xVal and yVal are of type
int.

Integer zVal = calcResult(xVal, yVal);

Autoboxing
Unboxing
Both - answer a

API is short for ___.
Authoring Program Instructions
Applied Programming Implementation
Application Programming Interface
Automated Program Instructions - answer c

What is the blueWidget's inStock at the end of main( )?
public class Widget {
private int inStock;
public Widget() {
inStock = 10;
}
public void addInventory(int amt) {
inStock = inStock + amt;
}
public static void main(String [] args){
Widget blueWidget = new Widget();
Widget greenWidget = new Widget();
blueWidget.addInventory(15);
greenWidget.addInventory(5);
}
}
}

25
10
30

Written for

Institution
CSC - Cyber Secure Coder
Module
CSC - Cyber Secure Coder

Document information

Uploaded on
September 22, 2024
Number of pages
12
Written in
2024/2025
Type
Exam (elaborations)
Contains
Questions & answers

Subjects

£10.66
Get access to the full document:

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF


Also available in package deal

Get to know the seller

Seller avatar
Reputation scores are based on the amount of documents a seller has sold for a fee and the reviews they have received for those documents. There are three levels: Bronze, Silver and Gold. The better the reputation, the more your can rely on the quality of the sellers work.
Pogba119 Harvard University
Follow You need to be logged in order to follow users or courses
Sold
57
Member since
1 year
Number of followers
2
Documents
5246
Last sold
2 days ago
NURSING TEST

BEST EDUCATIONAL RESOURCES FOR STUDENTS

3.8

13 reviews

5
5
4
3
3
4
2
0
1
1

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their exams and reviewed by others who've used these revision notes.

Didn't get what you expected? Choose another document

No problem! You can straightaway pick a different document that better suits what you're after.

Pay as you like, start learning straight away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and smashed it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions