Computer Science 201: Data Structures & Algorithms Ch. 2

0.0(0)
Studied by 0 people
call kaiCall Kai
Locked
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/44

encourage image

There's no tags or description

Looks like no tags are added yet.

Last updated 10:54 PM on 8/9/26
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai
Chat

No analytics yet

Send a link to your students to track their progress

45 Terms

1
New cards

An object-oriented design consists of periodical and publication data. The hierarchy of classes, from top to bottom is as follows: Publication -> Book -> Novel. If the Novel class gains all methods and fields from the Book class, this is an example of which of the concepts of Object Oriented Design?

Inheritance

2
New cards

You are designing a program for payroll. The Tax class has a method to calculate tax rates based on pay. You want to keep this method and its variables invisible to other classes. They can access the method but don't get to see its details. This is an example of _____.

Encapsulation

3
New cards

A parent class called SoftDrink has a brew() method. RootBeer and Beer classes inherit from SoftDrink. Each uses the brew() method but in different ways. Which aspect of object-oriented design is this?

Polymorphism

4
New cards

You are designing a program for vehicles. Some of the class names include Semi, Compact, and SUV. If we create a new semi, it is said that the semi is a(n) _____ of a(n) _____.

instance; Semi class

5
New cards

You have designed a hierarchy of classes for accounting software. All parent/child class relationships are set. What will you need for the classes to actually perform tasks?

Methods

6
New cards

How do functions differ from methods?

7
New cards

A _____ is a procedure associated with a class that describes an action an object is able to perform.

method

8
New cards

Sally is continuing work on her Object-Oriented Program and is writing code for a car, truck, and bus. These items under the class called vehicle are referred to as _____.

objects

9
New cards

Which of the following is NOT a core concept of object-oriented programming?

Inference

10
New cards

Sally is writing some Object-Oriented Program code for a vehicle that contains the attributes manufacturer, color, and price, along with what she wants the vehicle to be able to do which includes start, drive, and park. To do this, she needs to create a _____ for vehicles.

class

11
New cards

A parent class is also called a _____

Superclass

12
New cards

The method of the parent class can be re-used and modified in a subclass inherited from the parent class. What is the term used to reference this behavior?

Overriding

13
New cards

Examine the following code. Which variable CANNOT be used in the parent class of Benefit?

https://study.com/cimages/multimages/16/java_inheritance_q1.png

Both coverageOption and employeePremium cannot be used.

14
New cards

Which phrase accurately describes the relationship between the subclass BlueChip and the parent Stock?

BlueChip is a Stock

15
New cards

Which of the following correctly creates a subclass, or child class, from the main Employee class?

https://study.com/cimages/multimages/16/java_inheritance_q2_a1.png

16
New cards

An abstract class cannot _____

Be instantiated

17
New cards

Which of the following correctly shows the Oval class using the Shape interface?

public class Oval implements Shape {}

18
New cards

Out of the four possibilities listed, which of the following class names would be suitable as an abstract class?

Shape

19
New cards

Java doesn't allow _____, meaning one class cannot inherit from more than one parent class.

Multiple inheritance

20
New cards

Of the following types, what type of class would Product be?

https://study.com/cimages/multimages/16/java_interface_abstract_q5.png

Abstract

21
New cards

In an abstract data type, we say that the functions and data are _____ within it.

Encapsulated

22
New cards

These methods in an abstract data type are not available outside of it.

Private

23
New cards

Which of the following is not an example of an abstract data type?

Method

24
New cards

What best describes abstraction?

Running functions without knowing the code

25
New cards

Which of the following would violate representational independence in an abstract data type?

A Deck data type having a coin flip method

26
New cards

What could you change to make the following code not result in a error?

interface A {

public int one();

public int two();

public int three();

}

public class B implements C {

public int one() {

return 1;

}

}

Change ''implements C'' to ''implements A''

27
New cards

What does it mean for a data type to be abstract?

The ways its behaviors are implemented are not defined.

28
New cards

Which Java language construct is commonly used to create abstract data types?

Interfaces

29
New cards

Which is true about an interface definition?

The methods have no bodies.

30
New cards

What keyword is used when creating a class that uses an interface?

Implements

31
New cards

Code that catches an exception and performs other code is called a(n) _____

Exception handler

32
New cards

Which of the following code samples will create an exception in Java?

https://study.com/cimages/multimages/16/1979387086_java_exceptions_ex_q1_a1.png

33
New cards

Examine the following code. What will happen if the file myfile.txt is not found?

https://study.com/cimages/multimages/16/java_exceptions_ex_q2.png

A message will be displayed

34
New cards

Which of the following exceptions will occur if you try to reference an index of an array that doesn't exist?

ArrayIndexOutOfBoundsException

35
New cards

Java keeps a list of exceptions and will know what exception has occurred. Where are these stored?

Exception class

36
New cards

How is a static member different from a non-static member?

Static members are not associated with individual objects.

37
New cards

If you have a class called IceScraper nested within the class Car, which of these would be the correct way to instantiate an IceScraper object?

Car.IceScraper ice_scraper = new Car.IceScraper();

38
New cards

When do you have access to a static nested class?

when the containing class is loaded

39
New cards

Why might you want to use a static nested class?

You want to package one class with another.

40
New cards

What would be the output of the following code?

https://study.com/cimages/multimages/16/java_static_nested_class_ex.png

5

41
New cards

Given the following class definition in Java, which statement correctly accesses the printStatus method?

public class NetStatus {

int statusCount = 23;

public class NetStatusDetail {

public void printStatus() {

System.out.println('Your Detail = ' + statusCount);

}

}

}

NetStatus nets = new NetStatus();

NetStatus.NetStatusDetail netDetail = nets.new NetStatusDetail();

netDetail.printStatus();

42
New cards

In the following code, what is the name of the inner class?

https://study.com/cimages/multimages/16/java_inner_classes_q1.png

Book

43
New cards

Examine the following code: Which of the following correctly creates an instance of both the Product and the ProductDetail (a non-static inner) class?

pubilc class Product {

public class ProductDetail {

}

}

https://study.com/cimages/multimages/16/java_inner_classes_q3_a1.png

44
New cards

Examine the following code. There is a static inner class (ProductDetail) inside the outer class (Product). What is the correct way to create an instance of the ProductDetail class?

public class Product {

long productCode;

public static class ProductDetail {

long productCode;

public void display() {

System.out.println(this.productCode);

}

}

}

Product.ProductDetail pd = new Product.ProductDetail();

45
New cards

Examine the following code. What type of class is ProductCode?

https://study.com/cimages/multimages/16/36509313_java_inner_classes_q2.png

Local