CHAPTER 10: Object-Oriented Thinking

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

True or False : a code defined in the main method can be reused

False, you would need to define a static method in order to reuse the code

Why are both aggregation and composition together referred to as composition ?

They are represented using classes in the same way.

Composition

This is when an object consists of other objects. Aggregation between two objects is also referred to as composition.

What is the wrapper class used for?

To wrap primitive type values in an object because primitive type values are not objects.

What is unboxing

Unboxing is conversion from a primitive value type to an object.

To add b1 to b2, you write ___. A. b1.add(b2); B. b2.add(b1); C. b2 = b1.add(b2); D. b2 = b2.add(b1); E. b1 = b2.add(b1);

c and d

The subject object is called an _____ object and its class is called an _____ class.

aggregated, aggregated

The owner object is called an ____ object and its class is called an ___ class.

aggregating, aggregating

What are the common relationships among classes

association, aggregation, composition and inheritance

Object oriented paradigm

couples data and methods together into objects

which method can throw an Arithmetic Exception and how can you solve it?

divide. Use : ivide(BigDecimal d, int scale, int roundingMode) method to specify a scale and a rounding mode to avoid this exception, where scale is the maximum number of digits after the decimal point. For example, the following code creates two BigDecimal objects and performs division with scale 20 and rounding mode BigDecimal​.ROUND_UP.

What is UML notation of aggregation

empty diamond on aggregating class

t/f the following code changes the the value of "s" : String s = "Java"; s = "HTML";

f, it creates a new string object and assigns its reference to "s" and now the first one cannot be accessed.

T/F BigInteger and BigDecimal both accept type "integer"

false, they accept type string

In UML, an aggregating class is denoted as a _____to denote the composition relationship with an aggregated class

filled diamond

Association

general binary relationship that describes an activity between two lasses

Multiplicty: m...n

indicates the number of objects between m and n inclusively

Suppose a reference variable of type Integer called myInt is already declared. Create an object of type Integer with the initial value of 1 and assign it to the reference variable myInt.

myInt = new Integer(1);

To create an instance of Big integer for 454 what do you write?

new BigInteger("454");

What is the output of the following code?public class Test { public static void main(String[] args) {String s1 = new String("Welcome to Java");String s2 = s1;s1 += "and Welcome to HTML";if (s1 == s2)System.out.println("s1 and s2 reference to the same String object");elseSystem.out.println("s1 and s2 reference to different String objects");}} A. s1 and s2 reference to the same String object B. s1 and s2 reference to different String objects

b

What is the term used to describe converting a primitive value to a wrapper object

boxing

Which two classes can represent integers or decimal numbers of any size and precision

BigInteger and Big Decimal

What is UML notation of compositon

solid diamond on aggregating class

t / f : The compiler will automatically box a primitive value that appears in a context requiring an object, and will unbox an object that appears in a context requiring a primitive value.

t

t / f biginteger and bigdecimal are immutable

t

t/f string objects are immutable

t

t/f strings are objects

t

Class contract

the collection of methods and fields that are accessible from outside a class, together with the description of how these members are expected to behave.

Class encapsulation

the details of implementation are encapsulated and hidden from the user | combining of methods and data into a single data structure

Multiplicity *

unlimited number of objects

What is the output of the following code? public class Test { public static void main(String[] args) { java.math.BigInteger x = new java.math.BigInteger("3"); java.math.BigInteger y = new java.math.BigInteger("7"); x.add(y); System.out.println(x);

3, remember its immutable

Procedural Paradigm

An approach to programming where the programmer defines the steps for solving a problem | it focuses on designing methods (behaviors)

___________ is attached to the class of the composing class to denote the aggregation relationship with the composed object.

An empty diamond

What is the syntax to create a string from a string literal?

String newString = new String(stringLiteral) where string literal is a sequence of characters enclosed inside double quotes

What is the output of the following code?public class Test { public static void main(String[] args) {String s1 = new String("Welcome to Java!");String s2 = s1.toUpperCase();if (s1 == s2)System.out.println("s1 and s2 reference to the same String object");else if (s1.equals(s2))System.out.println("s1 and s2 have the same contents");elseSystem.out.println("s1 and s2 have different contents");}} A. s1 and s2 reference to the same String object B. s1 and s2 have the same contents C. s1 and s2 have different contents

a

Which of the following statements is preferred to create a string "Welcome to Java"? A. String s = "Welcome to Java"; B. String s = new String("Welcome to Java"); C. String s; s = "Welcome to Java"; D. String s; s = new String("Welcome to Java");

a

An aggregation relationship is usually represented as __________ in ___________.

a data field/the aggregating class

Multiplicity

a number or an interval that specifies how many of the class's objects are involved in the relationship

aggregation

a special form of association that represents an ownership relationship between two classes. It models has-a relationships. An object can be owned by several other aggregating objects.

Class abstraction

a technique in software development that hides detailed implementation. It hides the implementation of the class from the client. If you decide to change the implementation the client program will not be affected.

What are autoboxing and autounboxing? Are the following statements correct? a. Integer x = 3 + new Integer(5); b. Integer x = 3; c. Double x = 3; d. Double x = 3.0; e. int x = new Integer(3); f. int x = new Integer(3) + new Integer(4);

a. Correct, this is same as x = new Integer(3 + 5); b. Correct c. Wrong, this is same as Double x = new Integer(3); d. Correcte. Correct f. Correct


Kaugnay na mga set ng pag-aaral

Final Exam Review for Chapter 6-9

View Set

Exam 3 Test Bank: Mgmt. of pts. w/ oncologic or degenerative neuro disorders

View Set

NUR 243 PrepU Ch 2 Factors Influencing Child Health

View Set

Rotator Cuff Muscles: Location & Function

View Set

Mastering A&P: Anatomy and Physiology Unit Two Chapter Six

View Set

Chapter 7: Emotional Development

View Set

Sustainable architecture Final Exam

View Set

Ch.28- Kidney & Ureter Disorders; Ch.29 Bladder & Urethra

View Set