Programming Principles II Final Exam

¡Supera tus tareas y exámenes ahora con Quizwiz!

Inheritance is represented by a(n) ________________ with pointing to the ______________ in UML. a) arrow/subclass b) diamond/subclass c) arrow/superclass d) diamond/superclass

c) arrow/superclass

In Java, those entities are modeled in a ______________, a template (blueprint) that defines the state and behavior. a) thing b) item c) class d) object

c) class

Aggregation models the "________________" relationship between classes. a) is a b) is not like a c) has a d) is kind of

c) has a

How do random access files work?

moving the file pointer around to wherever we wanted based on bytes, then operations can be completed from that current position

What is a recursive method?

a method that calls itself

What major responsibility does a class have when inheriting from an abstract class or implementing an interface? a) Implement all abstract methods b) Create new constructors c) Override all inherited methods d) Provide accessors and mutators

a) Implement all abstract methods

How does java accomplish binary input/output?

Binary I/O uses specific classes to accomplish input/output but is very similar to the text I/O classes

How does event-driven programming differ from procedural programming? Address both strengths and weaknesses of event-driven programming.

Event Driven Programming- event driven programming will only start its chain of events when the source code is fired. For example a button being pressed. Which would then send it to the handler and finally the listener. Procedural Programming- procedural programming will go line by line method by method and run the program. It goes in order. They both have disadvantages and advantages. procedural allows you to keep everything in order and exactly how you want it, but that also means it can only run correctly a certain way. Event driven allows you place your code in however order you want, due to the fact that the code will only run when the user takes action.

Choose two Panes from JavaFX and provide a brief description of how each Pane works in terms of automatic placement of Nodes and automatic spacing/padding. Enough detail should be included to uniquely distinguish the Pane from other Panes.

Grid Pane- This allows you to sort your nodes in rows and columns. Stack Pane- the main outcome of the stack pane will basically just continue to stack all of the nodes on top of each other. For example if i create two buttons. They will be stacked on top of each other.

List a single visibility modifier that has been discussed, how it is depicted in UML, and what type of access that modifier provides to a data member to users of the class.

Private - provides access only within the class for the data member

List a single visibility modifier (different from previous) that has been discussed, how it is depicted in UML, and what type of access that modifier provides to a data member to users of the class.

Public + access is granted to all other classes within the package

Where is the default implementation of toString() provided? Choose the most correct answer. a) Object class b) JVM c) parent class d) developer

a) Object class

How are static members different from instance members?

Static members are shared within an entire class, whereas instance members refer to specific objects.

Assume that Sock is the superclass of WoolSock. Answer whether the following cast will succeed and briefly explain your answer. Sock s2 = new WoolSock();

The cast will succeed due to object casting. The object created in the subclass WoolSock will be able to be called by an object referenced in its superclass.

Describe how the Comparable interface's compareTo() method is expected to work according to Java convention. What should this method return and why?

The compareTo() method evaluates the value of two like objects. If the object being compared to is less than object being compared to then a negative integer is returned. If both objects are equivalent a 0 is returned. If the object being compared is greater than a positive integer is returned.

Assume that Sock is the superclass of WoolSock. Answer whether the following cast will succeed and briefly explain your answer. Sock s = new WoolSock(); WoolSock ws = s;

This code will not be cast since an object of the superclass Sock may not necessarily be the same type as the object of subclass WoolSock.

Assume that Sock is the superclass of WoolSock. Answer whether the following cast will succeed and briefly explain your answer. Sock s3 = new WoolSock(); WoolSock ws3 = (WoolSock)s;

Yes, since the subtype '(WoolSock)' is specified, Java is able to read s as an object of the subclass WoolSock.

When attempting to gather user input through TextFields in JavaFX, what are some considerations/precautions that must be made?

`when using a text field one consideration to make is the preset value of the text field. This notion will allow the user to see a preset value so they understand what to put in the text field. Precautions to make would me to add max and min sizes to the text field when the user actually puts their input into the field. You also want to make sure that the user can not change preset values you have set as the programmer

Inheritance models the "_______________" relationship between classes. a) is a b) is not like a c) has a d) is kind of

a) is a

Casting from a _____________ to a _____________ is considered a downcast. a) superclass/subclass b) primitive type/wrapper class c) subclass/superclass d) wrapper class/primitive type

a) superclass/subclass

What are the advantage/disadvantages to binary IO?

advantages of binary files is that they are more efficient to process than text files. Disadvantages being that the format is very meticulous therefore if you do not know it inside and out it will not work.

What are some advantages of object-oriented programming over procedural programming?

an advantage of object oriented programming over procedural is that it is keeps everything organized in order and is more real world practical. it is also much more efficient than procedural in that you can reuse code through inheritance.

What makes a marker interface (like Cloneable) uniquely different from non-marker interfaces? a) Clones object instances b) Empty interface that contains no methods c) Gives the class a usable name d) Represents a characteristic of the class

b) Empty interface that contains no methods

Text file I/O in Java requires the use of the _____________ class for input, and the ______________ class for output. a) Scanner/System.out b) Scanner/PrintWriter c) InputFile/OutputFile d) PrintWriter/Scanner

b) Scanner/PrintWriter

Abstract classes generally have protected constructors. What is the purpose of having these constructors marked protected? a) To allow access to all packages b) To allow access to subclasses c) To allow access to users d) To allow access to superclasses

b) To allow access to subclasses

OOP entities and their properties, including any relationships to other entities, can be visually represented using ________________ that uses symbols like rectangles, lines, and other shapes. a) Unified Model Language b) Unified Modeling Language c) Uniform Modeling Language d) Uniform Model Language

b) Unified Modeling Language

In Java code, how can a class indicate that it is implementing multiple interfaces? a) Using a comma list of interfaces before the implements keywords b) Using a comma list of interfaces after the implements keyword c) Using multiple implements keywords after any extends keywords d) Using multiple implements keywords before any extends keywords

b) Using a comma list of interfaces after the implements keyword

How does Java know what constructor to use when invoked? Choose the most correct answer. a) JVM chooses an implemented constructor b) Using method matching c) Order of parameters d) Number of parameters

b) Using method matching

To prevent direct modification of a data member, the member should have a visibility of __________________. a) public b) private c) final d) default

b) private

What is the purpose of object-oriented programming?

object oriented programming has a main purpose of implementing real world entities like inheritance, hiding, polymorphism etc.

What is the purpose of the toString() method? Choose the most correct answer. a) to describe all data members and their values b) to provide a textual representation of the object c) to provide some information to the developer d) to convert numeric data members into String values

b) to provide a textual representation of the object

How can we store and retrieve instances of objects in java?

by using the serializable marker interface

When working with both binary and text files, it is recommended to use try-with-resources. What major functionality does this mechanism provide? a) Allows exceptions in input to be caught and handled b) Allows programmers to create resources for use in input/output c) Allows for created resources to be auto-closed once the block is done executing d) Allows programmers to read and write text files

c) Allows for created resources to be auto-closed once the block is done executing

What is the main purpose of using exceptions? a) To allow a program to respond to user input in multiple ways b) To allow both text and binary file input and output c) To allow a program to continue to execute and/or recover from unexpected errors d) To prevent users from entering bad input into a running program

c) To allow a program to continue to execute and/or recover from unexpected errors

What is the purpose of an abstract class in OOP? a) To provide commonality between related or unrelated classes b) To create a blank template class c) To provide commonality between related classes d) To define classes that the user cannot instantiate

c) To provide commonality between related classes

In object-oriented programming, dynamic binding. __________________________________. a) allows the JVM to match method implementations to declared type at runtime b) allows the JVM to match method implementations to actual type at compile time c) allows the JVM to match method implementations to actual type at runtime d) allows the JVM to match method implementations to declared type at compile time

c) allows the JVM to match method implementations to actual type at runtime

Constructor chaining is _________________________________. a) having multiple constructors in a class to allow users to customize their instances b) when constructors call other constructors using the this() or super() keywords c) an automatic process used in inheritance for classes to obtain their superclass's properties d) using the constructors in a class to set specific object member values

c) an automatic process used in inheritance for classes to obtain their superclass's properties

In object-oriented programming, polymorphism __________________________________. a) means "many forms" or "many shapes" b) is the ability for a class to be referred to using the data types of any subclasses or related classes c) is the ability for a class to be referred to using the data types of superclasses and/or interface types d) allows a class to be referred to using any data type at any time

c) is the ability for a class to be referred to using the data types of superclasses and/or interface types

When cloning objects (using Cloneable or manually), which statements are true about shallow and deep copies? a) A shallow copy correctly clones only objects with primitive types b) A deep copy correctly clones objects with both primitive and reference types c) Shallow and deep copies are exactly the same, but deep copies take more processing and memory d) Both a) and b) are true statements e) a) b) and c) are all true statements

d) Both a) and b) are true statements

Modification of encapsulated data members require ____________ and ____________ methods. a) accessor/mutator b) retrieve/change c) get/set d) Both a) and c) are correct e) a), b), and c) are correct

d) Both a) and c) are correct

What is the connection between abstract classes/interfaces and polymorphism, if any? a) Both exhibit the "many forms" behavior since many classes can use them b) Abstract classes can be used to represent many different types of classes c) Interfaces can only be used by classes that have a strong relationship to the interface d) Both can be used as the data type for any class extending/implementing them

d) Both can be used as the data type for any class extending/implementing them

The _________________ relationship is represented by the hollow diamond shape in UML. a) binary b) composition c) association d) aggregation

d) aggregation

The _________________ relationship is represented by the filled diamond shape in UML. a) association b) aggregation c) binary d) composition

d) composition

In Java, the set of __________________ define the behavior of an entity. a) values b) data members c) properties d) methods

d) methods

How are constructors invoked outside of the class in Java? Choose the most correct answer. a) Developer writing a test program b) this keyword c) public keyword d) new keyword

d) new keyword

A(n) __________________ represents a real-world entity that can be distinctly identified. a) item b) class c) thing d) object

d) object

In Java, the set of data members and their current values model the ___________________ of an entity. a) existence b) properties c) behavior d) state

d) state

What does the super keyword provide access to when used in a Java class? a) current class members b) package members c) subclass members d) superclass members

d) superclass members

In Java, exception handling makes use of a _________/___________ block to detect and handle Exceptions. a) catch/finally b) run/exception c) try/finally d) try/catch

d) try/catch

What is the difference between binary and text file?

data stored in text file is represented in human readable form, where as a binary file is in binary form, they are meant to be read by programs and not humans

Protected visibility on a data member allows access to _______________________________. a) class b) package c) subclass d) superclass e) Both b) and c) are correct f) a), b), and c) are correct g) a), b), c) and d) are correct

f) a), b), and c) are correct

How is an ArrayList different from a "regular" array? a) Allows access to convenience methods not accessible with regular arrays b) Dynamically sized to allow for easy insertion and removal c) Can contain both reference and primitive types d) Requires the user to specify a concrete type e) All except a) f) All except b) g) All except c) h) All except d)

g) All except c)

Which class components does the this keyword provides access to when used in a Java class? a) data members b) constructors c) methods d) Both b) and c) are correct e) Both a) and b) are correct f) Both a) and c) are correct g) a), b), and c) are correct

g) a), b), and c) are correct

What is recursion?

is a technique that leads to elegant solutions for problems that are difficult to solve with iteration

Why do lambda expressions only work with Single Abstract Method (SAM)/functional interfaces?

lambda functions can only provide the implementation for 1 method it is mandatory for the functional interface to have ONLY one abstract method.

Class component: Data Members Provide the recommended visibility modifier that Java convention dictates is usually appropriate for the provided class component. Give a brief description for why that modifier is used.

private. Private is best so that the value of data type is not altered.

Class component: Constructors Provide the recommended visibility modifier that Java convention dictates is usually appropriate for the provided class component. Give a brief description for why that modifier is used.

public. The public modifier is best so that the constructor can be accessed in the "main" method for instances to be created.

Class component: Method Members Provide the recommended visibility modifier that Java convention dictates is usually appropriate for the provided class component. Give a brief description for why that modifier is used.

public. This is best so that members can be accessed between methods within the class and be called by an instance outside the class.

What are the advantages of using buffers?

the main advantage of using a buffer is to speed up I/O

What is the purpose of a static member?

the purpose of a static member is when we want to share properties between all instances of a class. For example it can be accessed before any objects of its class are created.

How do we use buffers when doing binary I/O?

wrapping an additional constructor around our file objects


Conjuntos de estudio relacionados

Economics & Pers Finance B - Types of Insurance

View Set

U6A1 Proctored Cancer Test | BSC1005

View Set

(INTRODUCTION TO WORD PROCESSING)

View Set

Guaranteed Exam Missed Questions#1

View Set

Med Surg: Chapter 41: Nursing Management: Patients With Musculoskeletal Disorders: PREPU

View Set

CH 20 DNA Replication and Repair

View Set

IST 294 Ethical Hacking Chapter 5 - Port Scanning

View Set

Engineering - Electronic Components Review

View Set