Chapter 7: Object-Oriented Programming Overview

Ace your homework & exams now with Quizwiz!

When using multiple interfaces to mimic multiple inheritance, what keyword is added before the declaration?

@Override

Examine the following code what will happen if the file my file.txt is not found? try{ FileInputStream thisFile = null; thisFile = new FileInputStream('my file.txt"); } catch (FileNotFoundExcepton e) { System.out.println("File not found"); }

A message will be displayed

After constructing a specific object, the Java new operator returns ____

A reference to the object

Of the following types, what type of class would Produce be? public class BrilloPad extends Product { public long getThreads(long t) { return t; } }

Abstract Since Product is a fairly generic concept, it would make more sense if it were abstract. You wouldn't be able to create instances of Product classes; but it does make sense to create an instance of a Brillo Pad.

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

ArrayIndextOutOfBoundsException

An abstract class cannot_______

Be instantiated You cannot create an instance of an abstract class/instantiate one. It is better used for hierarchies: Think of it as a model. You could have a Vehicle class that is abstract, with Truck, SUV, or Semi as classes under it.

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

BlueChip is a stock

Examine the following methods. We need to add another method with the same name (overload the methods), to add two values together. What must be true about these new arguments? public double calcValues(double rate, double percentage) { return rate * percentage; } public double calcValues(double rate, double percentage, double )} return rate * percentage * modifier: }

Both cannon be double You can have two methods with the same number of arguments, but they can't both be double values, since we already have two of them in this example.

class Employee { public Employee(double r) { payRate = r; } public Employee(double z) { payRate = z; } }

Cannon create two identical contractors Overloading doesn't mean cloning! You can't create two identical constructors. Even though the parameters are different, each constructor has one parameter.

Examine the following constructor. Which code snippet correctly creates a new instance of the Cards class? class Cards { String suit; public Cards(String suit) { this.suit = suit; } }

Cards ace = new Cards("Diaminds");

In which class can yo override a method?

Child

Sally is writing some Object-Oriented Program code for a vehicle which contains the attributes ( manufacturer, color, and price), along with what she wants the vehicle to be able to do (start, drive, and park). This is know as a ________

Class

The line of code that creates an object from the class is called a ______

Constructor

Which code snippet will create/instantiate a new instance of the Customer class?

Customer name = new Customer();

You can have overloaded methods of the same name and number of parameters, if only the________are different?

Data types

The _______ Problem describes the complexity of multiple inheritance in Java?

Diamond

Information can be ______ in Java class, meaning availability only to that class?

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 We need to hide the data or encapsulate it. You can still call the calculateTax() method in the Tax class, without having to know exactly how the tax is being calculated, or even what the employee pay rate is. It's good practice to keep things restricted/encapsulated. Start with the tightest controls.

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 performed other code is called a(n) ________

Exception handler

How do functions differ from methods?

Functions are independent of classes, and methods are defined within a class

When overriding a method, where is the new method defined?

In the child class

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

Inference Four core concepts of object-oriented programming are abstraction, encapsulation, inheritance and polymorphism. Note that inference is NOT a core concept.

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

Inheritance

Overriding methods in Java is part of the overall concept of_________

Inheritance

_______ means that classes can share the properties and methods from other classes

Inheritance

An instance of a class______methods and variables from the main class?

Inherits

An instance of a class_____methods and variables from the main class?

Inherits

Examine the following code. It can be said that the class Banana_______ attributes from the class Fruit public class Banana extends Fruit(){ }

Inherits

An object is a(n)_____ of a class?

Instance

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

Int i = 7; int j = 0; int k = i / j;

Examine the following code. What is true about the method increaseSpeed()? public class boat { void increeaseSpeed() { //lncrease speed! } } public class SpeedBoat extends Boat { void increaseSpeed() { //go faster!! } }

It is overridden The SpeedBoat class inherits everything from the Boat class, including the methods. But in this case it is overridden and will go faster.

What happens if you don't create a constructor fro a class?

Java creates a default constructor class

From a technical perspective, why is multiple inheritance diffuse in Java?

Java loads classes dynamically. You can't know which method(s) are valid.

Polymorphism mean?

Many Forms

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

Method

Actions are performed on an object by calling its_______

Methods

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 that one parent class?

Multiple inheritance

Examine the following class declaration? Is this valid? public class NewClass extends HotSandwich extends Sandwhich { }

No, java doesn't support multiple inheritance

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

Examine the following code for the class Orders. Which of the following correctly instantiates a new instance of Orders? class Orders { long orderID; long qtyOnHand; public Orders(long orderID, long qtyOnHand) { } }

Orders myOrder = new Orders(1234, 14); Since there's a constructor, you can't just use new Orders(10,52). Nor can you create a new Orders instance without arguments, since you have created a constructor for it. It requires two values, orderID and quantity on hand.

Polymorphism supports________, which is several methods with the same name but different arguments?

Overloading

Examine the following code. The method getID is ________ in the subclass VipOrder? public class Order { public int getID(int orderID) { return orderID; } } public class vipOrder extends Order { public int get ID(int orderID) { Boolean vip = true; return order ID; } }

Overridden

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 Polymorphism refers to being able to perform the same thing but differently. Root beer is brewed, but not in the same way as beer. Yet each can use the brew() method in different ways.

Examine the following code for a class and its constrictor. What is the correct method to overload the instructor for a third argument? public class Employee { String employeeName; double payRate; double hoursworked; public Employee(String e, double r) f String empName = e; double pay = r; } }

Public Employee(String e, double r, double h) { String empName = e; double pay = r: double hours = h; } } To have a valid overload, we need to have a different number of arguments. We can't simply create another one with two.

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

Public class Oval implements shape {}

Which of the following code snippets illustrates a method of multiple inheritance in java?

Public class Z implement A, B {}

Which of the following statments correctly overrides the setQoh method? public long setQoh(long qty) { return qty; }

Public long setQoh(long qty) { qty = qty + 5; return qty; }

Which of the following classes would be suitable as an abstract class?

Shape

Which of the following is not a reason that Java prevents the use of multiple inheritance?

System performance

Examine the following code: The constructor is preventing it from compiling. What is wrong? class Cards { String suit; public DeckofCards(String suit) { this.suit = suit; } }

The name doesn't match the class

If you call an overloaded method that doesn't exist, what will happen?

The program will not compile

Examine the following code for the class Orders. Which of the following correctly instantiates a new instance of orders? class DiskDrive { double capacity; long modelNumber; double partitionSize; Public DiskDrive(double capacity, double modelNumber, double partitionSize) { } DiskDrive Seagate = new DiskDrive(0, 15);

The third parameter from the constructor The constructor has three arguments, but the code does not include all of them when it instantiates the instance of the class.

Examine the following code for a constructor. Which option will create a new instance of the Trees class and pass the parameter of elm to the constructor? public class Trees { String species; public Trees(String tree) { this. species = species; } }

Trees tree = new Trees('elm");

The same variable names can be used in the class and constructor. In the constructor, how do you differentiate them?

Use the this keyword

A ______ is a description of a group of objects that have common properties and behavior. It's a blueprint from which specific object are created?

class

A {Blank} must be specified before a specific instance of a Java object can be created.

class declaration

Examine the following code. Which method is being overridden? Public class Employee { public double lgetHours(double hours) { return hours; } } public class UnionEmployee extends Employee { public double getHours(double hours) { hours *= .0005; } ;public double getFees(double fees) { fees = .075; return fees; } }

getHours

Examine the following code. What is the name of the method that is being overwritten? public class Trees { double avgAge; double avgHeight; public double getTreeInfo(){ return avgAge; } } public class AshTree extends Trees { int classCode = 5; public double getTreeInfo(){ return classCode; } }

getTreeinfo

You are designing a program for vehicle. 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 specific instance of a class is created using the_______operator

new

Examine the following code that defines a class for bonds. Which of the following is correct way to override the method calcFees? Public class Bonds { double apr = .0275 double load = .0003; public double calcFees() { return apr + (load * 1.5); } }

public class ABonds extends Bonds { double adminFee = 1; public double calcFees() { return double calcFees() { return adminFee + (apr * load); } }

Which of the following shows an overloaded method for setCost:?

public class Invoice { public double setCost(double cost) { return cost; } public double setCost(double cost, int cID) { return cost; } }

If you have overridden a method but still want to use the parent class method, what keyword is used?

super

A parent class is also called a_____

superclass


Related study sets

2. BUS 110 Intro to Business Ch 5 Summary

View Set

Economics - Unit 1: What Is Money

View Set

a&p chapter 8: skeletal system- axial and appendicular skeleton

View Set

Unit 5: Applying Transitions & Animations

View Set

Business Communications Final Exam

View Set

Domain 1 (CISA Review Questions, Answers & Explanations Manual, 12th Edition | Print | English)

View Set

PrepU Management of Patient with Upper Respiratory Tract Disorders

View Set