Computer Science 201: Data Structures & Algorithms Ch. 2
What would be the output of the following code? https://study.com/cimages/multimages/16/java_static_nested_class_ex.png
5
Which of the following would violate representational independence in an abstract data type?
A Deck data type having a coin flip method
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
Of the following types, what type of class would Product be? https://study.com/cimages/multimages/16/java_interface_abstract_q5.png
Abstract
Which of the following exceptions will occur if you try to reference an index of an array that doesn't exist?
ArrayIndexOutOfBoundsException
An abstract class cannot _____
Be instantiated
Which phrase accurately describes the relationship between the subclass BlueChip and the parent Stock?
BlueChip is a Stock
In the following code, what is the name of the inner class? https://study.com/cimages/multimages/16/java_inner_classes_q1.png
Book
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.
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();
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''
In an abstract data type, we say that the functions and data are _____ within it.
Encapsulated
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
Java keeps a list of exceptions and will know what exception has occurred. Where are these stored?
Exception class
Code that catches an exception and performs other code is called a(n) _____
Exception handler
What keyword is used when creating a class that uses an interface?
Implements
Which of the following is NOT a core concept of object-oriented programming?
Inference
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
Which Java language construct is commonly used to create abstract data types?
Interfaces
Examine the following code. What type of class is ProductCode? https://study.com/cimages/multimages/16/36509313_java_inner_classes_q2.png
Local
Which of the following is not an example of an abstract data type?
Method
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
Java doesn't allow _____, meaning one class cannot inherit from more than one parent class.
Multiple inheritance
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();
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
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
These methods in an abstract data type are not available outside of it.
Private
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();
What best describes abstraction?
Running functions without knowing the code
Out of the four possibilities listed, which of the following class names would be suitable as an abstract class?
Shape
How is a static member different from a non-static member?
Static members are not associated with individual objects.
A parent class is also called a _____
Superclass
Which is true about an interface definition?
The methods have no bodies.
What does it mean for a data type to be abstract?
The ways its behaviors are implemented are not defined.
Why might you want to use a static nested class?
You want to package one class with another.
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
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
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
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
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
A _____ is a procedure associated with a class that describes an action an object is able to perform.
method
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
Which of the following correctly shows the Oval class using the Shape interface?
public class Oval implements Shape {}
When do you have access to a static nested class?
when the containing class is loaded