Object- Oriented Thinking Flashcards

(26 cards)

1
Q

what is class abstraction in Java?

A

is the separation of class implementation details from users of the class. It also hides implementation details, exposing only necessary information to the users of the class.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Class Contract

A

Signatures of public methods and public constants

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Violate Encapsulation

A

Is the practice of keeping instance variables public and providing services to clients of the class

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Enforce Capsulation

A

Is the practice of keeping variables private and supporting other methods in the class

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How do you design a class with encapsulation?

A

Define instance variables as private and provide public methods (getters/setters) to interact with them.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What are the characteristics of a loan object?

A

Borrowed amount (variable), interest rate (variable), start date (variable), loan duration (variable), monthly payment (method), and total payment (method).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How is encapsulation achieved in a class?

A

By making variables private and providing public getters/setters and private support methods.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What methods does the loan class include?

A

Getters, setters, monthly payment, total payment, and constructors.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is the default constructor in the Loan class?

A

It initializes a loan with 2.5% interest, 1 year duration, and $1000 loan amount.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What does TestLoanClass demonstrate?

A

Creating a loan object from user input and displaying loan info like date and payment.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What attributes does the BMI class have?

A

Name, age, weight (lbs), and height (inches)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What are the BMI class constructors?

A

One with name, age, height, another with default age = 20.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

How is BMI calculated?

A

Using the formula: weight in kg / (height in meters)^2, rounded to 2 decimals.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

How is BMI determined?

A

Underweight (<18.5), Normal (<25), Overweight (<30), Obese (30+)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What does UseBMIClass show?

A

Creating and using BMI objects to print BMI and status for individuals

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Why are wrapper classes used?

A

To treat primitive values like objects.

17
Q

Name Java wrapper classes for primitive.

A

Boolean, Character, Byte, Short, Integer, Long, Float, Double.

18
Q

What are two constructors for Inetger and Double?

A

One with a numeric value, and one with a string.

19
Q

Can wrapper objects be created from strings?

A

Tes, e.g., Integer (“90”), Double( “95.7”).

20
Q

What constants do numeric wrapper classes have?

A

MAX_Value and MIN_Value

21
Q

What methods convert wrapper objects to primitives?

A

intValue(), floatValue(), shortValue(), etc.

22
Q

What does value0f(String s) do in wrapper classes?

A

Creates a wrapper object from a string?

23
Q

what does parseInt(‘‘110’’), 2) return?

A

6 (binary to decimal conversion)

24
Q

What are boxing and unboxing?

A

Boxing wraps primitive into objects; unboxing extracts primitives.

25
When are BigInteger and BigDecimal used?
For a very large or high-precision numbers.
26
Are String objects mutable in Java?
NO, once created, their contents be changed.