Object- Oriented Thinking Flashcards
(26 cards)
what is class abstraction in Java?
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.
Class Contract
Signatures of public methods and public constants
Violate Encapsulation
Is the practice of keeping instance variables public and providing services to clients of the class
Enforce Capsulation
Is the practice of keeping variables private and supporting other methods in the class
How do you design a class with encapsulation?
Define instance variables as private and provide public methods (getters/setters) to interact with them.
What are the characteristics of a loan object?
Borrowed amount (variable), interest rate (variable), start date (variable), loan duration (variable), monthly payment (method), and total payment (method).
How is encapsulation achieved in a class?
By making variables private and providing public getters/setters and private support methods.
What methods does the loan class include?
Getters, setters, monthly payment, total payment, and constructors.
What is the default constructor in the Loan class?
It initializes a loan with 2.5% interest, 1 year duration, and $1000 loan amount.
What does TestLoanClass demonstrate?
Creating a loan object from user input and displaying loan info like date and payment.
What attributes does the BMI class have?
Name, age, weight (lbs), and height (inches)
What are the BMI class constructors?
One with name, age, height, another with default age = 20.
How is BMI calculated?
Using the formula: weight in kg / (height in meters)^2, rounded to 2 decimals.
How is BMI determined?
Underweight (<18.5), Normal (<25), Overweight (<30), Obese (30+)
What does UseBMIClass show?
Creating and using BMI objects to print BMI and status for individuals
Why are wrapper classes used?
To treat primitive values like objects.
Name Java wrapper classes for primitive.
Boolean, Character, Byte, Short, Integer, Long, Float, Double.
What are two constructors for Inetger and Double?
One with a numeric value, and one with a string.
Can wrapper objects be created from strings?
Tes, e.g., Integer (“90”), Double( “95.7”).
What constants do numeric wrapper classes have?
MAX_Value and MIN_Value
What methods convert wrapper objects to primitives?
intValue(), floatValue(), shortValue(), etc.
What does value0f(String s) do in wrapper classes?
Creates a wrapper object from a string?
what does parseInt(‘‘110’’), 2) return?
6 (binary to decimal conversion)
What are boxing and unboxing?
Boxing wraps primitive into objects; unboxing extracts primitives.