Object-Oriented Programming: Classes, Attributes, and Methods in Java

0.0(0)
studied byStudied by 0 people
0.0(0)
full-widthCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/26

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai

No study sessions yet.

27 Terms

1
New cards

A student is developing a class that will store information about pets, including each pet's name and age. Which set of attributes is most appropriate?

One String for the name and one int for the age

2
New cards

A student is developing a Player class that should allow access and modification of the score. Which attributes/behaviors are most appropriate?

A score attribute with getScore and setScore methods

3
New cards

A programmer reduces testing to speed up development. What is the most likely consequence?

Decreased system reliability

4
New cards

A software company created a program to help a community. Which statement is true about the program?

It could have unintended harmful effects beyond its intended use

5
New cards

Why do programmers often include open-source code in their programs?

To reuse implemented algorithms while reducing intellectual property concerns

6
New cards

Given Item class with private double price and public String name, code segment I accesses price, code segment II accesses name. Which prints?

Code segment II prints the name; code segment I does not compile

7
New cards

Candy class has public instance variables but should prevent modification. What change is needed?

Make the instance variables private

8
New cards

Which declaration is most appropriate for the Profile class with name, username, and followers hidden from external access?

public class Profile with private name, private username, and private followers

9
New cards

Person class missing constructor must allow Person p = new Person("Washington") to set name. Which constructor is correct?

public Person(String n) { name = n; }

10
New cards

Fruit class diagram missing quantity variable and method. Which replacements are most appropriate?

private int quantity and public int getQuantity()

11
New cards

Dog fido = new Dog(); printing name and age outputs what?

name: null, age: 0

12
New cards

Student("Bobby", 25) does not assign age correctly. What is the state of the object?

name is "Bobby" and age is 0

13
New cards

BankAccount deposit does not work: public void deposit(double amount){ double balance = balance + amount; }. Why not?

A local variable named balance shadows the instance variable, so the instance variable never updates

14
New cards

Thing apple = new Thing(5); Thing banana = new Thing(5); printing apple.mystery(banana) and banana.mystery(banana) outputs what?

maybe yes

15
New cards

Which code correctly completes Player.hasHigherScore(Player other)?

return this.getTotal() > other.getTotal();

16
New cards

Friend constructor uses name = name causing getName() to return null. What fix solves it?

Replace name = name with this.name = name

17
New cards

MyClass updateX leaves x unchanged when? updateX adds amount to x.

When the amount (num) is 0

18
New cards

In XYPoint.getPoint(), which code returns (x, y) correctly?

return "(" + x + ", " + y + ")";

19
New cards

Fraction.getDecimal() returns numerator/denominator. When does it fail to return a value?

When denominator is 0

20
New cards

mystery(String message,int x) returns message.substring(x). What happens for str1="abcde", str2=mystery(str1,3)?

str1 is unchanged; str2 becomes "de"

21
New cards

In getTax(Item myItem,double taxRate), which expression retrieves cost correctly?

myItem.getPrice()

22
New cards

Location clone method accesses private fields row and col. When does it work?

Only if defined inside the Location class

23
New cards

Which Widget.doSomething implementation allows Widget.doSomething() to compile?

public static int doSomething() { return word.length(); }

24
New cards

StringFinder code produces what output? jazz→target x then blaze→target a then zebra→target z

-1 2 0

25
New cards

ComputeObject s.sumProd(5) prints what?

100

26
New cards

Stars s = new Stars(3,2); s.draw(5); what prints?

then then * then ** then **** (one line each)

27
New cards

TestObject obj1=new TestObject(2.5); obj2=new TestObject(10.2); obj1.printTestObject() prints what?

2.5, 2