oOP Flashcards
are the variables that each object (each instance of a class) has as part of itself.
instance variables
means they are accessible only to the object itself.
private,
returns a reference to the object it constructs
constructor
Parameter names follow the same rules as the other names you might pick for a program. Names of this type are called
this
is a variable that holds part of the state of an object.
instance variable
In Java, a characteristic of a class that is not part of its objects
static.
Can the static main() method invoke other static methods of the class?
Yes. Static methods can call other static methods.
Will parameter passing be the same as with the instance methods of the previous chapters?
Yes. Static methods pass data to other static methods through parameters.
The program keeps looping until the user signals the end. What type of loop is this?
A sentinel controlled loop.
What is the parameter of the method that calculates factorial?
The value of N, an integer
What is the return value of the method that calculates factorial?
The factorial of N.
is an incomplete version of a method that is used in place of the full method. Extremely useful when developing programs.
stub
let you test individual methods. This can be very useful.
unit testing
is one whose data does not change.
immutable object
The arguments in a method call are often referred to as ____.
actual parameters
A(n) ____ method is a method that creates and initializes class objects.
constructor
____ is the encapsulation of method details within a class.
Implementation hiding
When a variable ceases to exist at the end of a method, programmers say the variable____.
goes out of scope
Method names that begin with “____” and “set” are very typical.
get
Public classes are accessible by all objects, which means that public classes can be
extend or/and used as a basis
Assigning ____to a field means that no other classes can access the field’s values.
private access
Methods used with object instantiations are called ____ methods.
instance
Methods that retrieve values are called ____ methods.
accessors
A(n) unique identifier is most likely used as a(n) ____ key in a database.
primary
For ease in locating class methods, many programmers store them in ____ order.
alphabetical
A(n) ____ constructor is one that requires no arguments.
default
A(n) ____ is a program module that contains a series of statements that carry out a task.
method
The method ____ is the first line of a method.
declaration
executes first in an application, no matter where you physically place it within its class.
main method
Data items you use in a call to a method are called ____.
arguments
A(n) ____ variable is known only within the boundaries of the method.
local
A(n) _____ causes a value to be sent from a called method back to the calling method.
return statement
An object is a(n) ____ of a class.
member
for a class, you no longer have access to the automatically created version.
when you write a constructor
You are ____ required to write a constructor method for a class.
never
To execute a method, you ____________________ it from another method.
invoke
Access specifiers are also called access ____________________.
modifiers
When you think in an object-oriented manner, everything is a(n) ____________________.
object
A(n) ___________ is a number appended to a field, typically an ID number or account number.
check-digit
so that other classes can instantiate objects that belong to the class.
You declare constructors to be object
First line of a method
header
Combination of the method name and the number, types, and order of arguments
methods signature
Included within the method declaration parentheses
parameter type
Are called class methods
static methods
Variables in the method declaration that accept the values from the actual parameters
formal parameter
Used to return value back to the calling method
return statement
Data components of a class
instance variables
Application or class that instantiates objects of another prewritten class
class user
Variables you declare within a class, but outside of any method
data fields
a method that allows you to create objects from a class. You call the constructor by using the keyboard new, followed by the name of the class followed by any necessary parameter
Constructor
A method that allows you to create objects from a class. you call the constructor by using the keyword new followed by the name of the class, followed by any necessary parameter
Constructor
a method name followed by parenthesis Ex. calculate()
call
Value passed to a method
Argument
part of the method that receives data must the same type and in the same order as it is stated in the method declaration
Method parameter
Blueprint in which objects are created
class
initial requirement of the method. It is normally stated as part of the methods documentation.
Precondition
Creating a new class based on a previously defined class
Inheritance
Class that inherits from another class
Subclass
Has a name, parameter, and a return type, but no code in the body of the method.
Abstract Method
Class that contains one or more abstract methods. Abstract classes may not be instantiate, and require subclasses to provide implementation for the abstract methods
Abstract Class
Methods that stores a value in a field or in some other way changes the value of a field
Mutators
Does not return a value
Void Method
Cause a methods to end and sends a value back to the statement that called the methods
return
Two or more methods with the same name but different parameter types, order, and/ or number of parameters. When overloaded methods are called, the compiler decides which one to use based on the number, order, and type of parameter.
Method overloading
Methods that gets a value from a class’s field, but does not change it
Accessors
Return the character at the specified index
char charAt(int index)
Returns number of characters in the string
int Length()
Return true if this string contains the same characters as str and false if it doesn’t. Ignores lower and upper case
boolean equalIgnore Case(String str)
Returns position of the first character in the first occurrence of str in this string
int indexOf(String str)
Returns new string that is the same except all letters are in lowercase
String toLower Case{}
returns - –uppercase
String toUpperCase()
Adds the specified string to the end of original string
-String concat(String str)
A(n) __ is a program module that contains a series of statements that carry out a task.
Methods
the method__is the first line of a methods
Declaration
Executes first in application no matter where you physically place it within its class
Main Method
Data items you use in a call to a method are called
Arguments
____is the encapsulation of method details within a class
Implementation Hiding
A(n)___variable is known only within the boundaries of the methods
- Local
When a variable cease to exist st the end of a method, programmers say the variable____
-Goes out of scope
The arguments in a methods call are often referred to as____
Actual Parameter
A(n)____causes a value to be ssent from a called method back to the calling metho
return statement
an object is a(n) ___ of a class
-Member
Methods names that begins with “___” and “set” are very typical
Public classes are accessible by all objects, which means that public classes can be
Extend or / and used as a basis
Assigning ____ to a field means that no other classes can access the field’s values
Private access
Methods used with objects intantiations are called _____methods
Instance
Methods that retrieve values are called _______methods
Accessors
A(n) unique identifier is most likely used as a(n) ____key in a database
Primary
A(n) _____methods is a methods that creates and initializes class objects
Constructor
For ease in locating class methods, many programmers stores them in ____ order.
Alphabetical
A(n) ___ constructor is one that requires no arguments
Default
You are ___required to write a constructor methods for a class
Never
to execute a method, you ____it from another methods
Invoke
Access specifiers are also called access___
Modifiers
When you think in an object-oriented manner, everything is a (n)____
Object
A(n) ____ is a number appended to a field, typically an ID number or account number
Check digit
So that other classes can instantiate that belong to the class
You declare constructors to be object
First line of method
Header
Combination of the methods name and the number, types, and order of arguments
Methods signature
included with the methods declaration parantheses
Parameter type
Are called class methods
Static methods
variables in the methods declaration that accept the values from the actual parameters
Formal statement
used to return value back to calling method
return statement
data components of a class
instance variable
application or class that instantiate objects of another prewitten class
class user
variables you declare within a class, but outside of any methods
data fields
a group of characters separated by spaces
token
preparing a disk file for reading
operating file
used to send characters to a text file
PrintWriter
data that is supplied to a method just before it starts running.
parameter
ArrayDemo.
3 Fundamental Features of OOP
1) encapsulation
2) inheritance
3) polymorphism
an object-oriented technique in which the internal details of an object are “hidden” in order to simplify their use and reuse
encapsulation
a relationship between two classes in which one class ( the subclass) inherits all of the properties and capabilities of another ( the superclass)
inheritance
declaring a variable to have one type while it refers to an object of a subclass of that type
polymorphism
a means of determining what aspects of a given problem can be viewed as objects in an eventual object-oriented design
object-oriented analysis
a software design method that models the characteristics of abstract or real objects using classes and objects.
object-oriented design
a programming technique that features objects, classes, encapsulation, interfaces, polymorphism, and inheritance.
object-oriented programming
degree to which responsibilities of a given component are a meaningful unit
cohesion
greater cohesion reflects better design; less coupling reflects better design.
cohesion vs coupling
degree to which one component must directly access the data of another component.
coupling
sets of responsibilities
roles
they are the same when a given role is always played by the same object type
roles vs. objects
3 Means of Object-Object Access
1) parameter passing
2) object declared in method
3) object is a member of another object through composition [subtype]
describes an inheritance relationship between two classes
is-a relationship
the relationship demonstrated by a class that contains another class
has-a relationship
implemented-in-terms-of relationship
uses-a relationship
known as “class variables”, because there is only one unique value for all the objects of that same class
static members
special reference that refers to the object in which it is used
this
special reference that refers to the superclass of the object in which it is used
super
Determine whether a subclass is a subtype
Liskov Substitution Principle
no outside classes can use this data field (except descendant classes), defeats the purpose of OOP
protected access
type cast to the type of an ancestor class; usually done automatically
upcasting
type cast to the type of a descendant class; may cause runtime errors
downcasting
UML diagram that captures all actors (an individual or another system) and use cases involved with a system or product; Used to model user requirements
use case diagram
a visual representation of the relationships between classes
class diagram
represents real-world whole-part relationships
e.g., an engine is a part of a car
composition
represents a class as a collection or container of other classes
aggregation
used to show that some UML element or a set of elements requires, needs or depends on other model elements for specification or implementation
dependency
minimum and maximum number of occurrences of one object for a single occurrence of related object
multiplicity
signifies the role that a participating entity type plays in each relationship instance. In some cases the same entity type participates more than once in a relationship type in different roles.
role name
a type of diagram that shows objects participating in interactions and the messages exchanged between them.
sequence diagram
this pattern ensures you have at most one instance of a class in your application
singleton pattern
the design pattern that provides a way to access the elements of an aggregate object sequentially without exposing the underlying representation.
iterator pattern
the design pattern that translates one interface for a class into a compatible interface
adapter pattern
- simplifies the interface of a group of classes,
- hides the complexity of one or more classes behind a clean, well-lit facade,
- makes an interface simple.
- provides a unified interface to a set of interfaces in a subsystem
facade pattern
1) Determines the requirements of a system
2) Focus on what needs to be done (not how)
3) Carried out by a team of analysts
4) End product is a conceptual model
Object-Oriented Analysis Stage
1) Major subsystems should be loosely coupled, allowing independence
2) Many-to-many relationships require an additional class
3) Avoid exposing details of business logic implementation to the user interface
4) Avoid exporting mutable objects
5) Avoid importing objects of an internal type in the system
5 Design Principles
aka “Single Dot Rule”
Long lists of method calls are attributed to bad design
Law of Demeter
Integer class is an example of Decorator pattern.
(a) True
(b) False
(a) True
In which of the following pattern an interface is responsible for creating a factory of related objects without explicitly specifying their classes?
(a) Factory Pattern
(b) Abstract Factory Pattern
(c) Singleton Pattern
(b) Abstract Factory Pattern
Which of the following describes the Structural pattern correctly?
(a) This type of patterns provide a way to create objects while hiding the creation logic, rather than instantiating objects directly using new operator
(b) This type of patterns concern class and object composition. Concept of inheritance is used to compose interfaces and define ways to compose objects to obtain new functionalities.
(c) This type of pattern are specifically concerned with communication between objects.
(b) This type of patterns concern class and object composition. Concept of inheritance is used to compose interfaces and define ways to compose objects to obtain new functionalities.
Which of the following is the correct list of entities of MVC pattern?
(a) Middle, Viewer, Controller
(b) Model, View, Control
(c) Model, Viewer, Control
(d) Model, View, Controller
(d) Model, View, Controller
Define a family of algorithms, encapsulate each one, and make them interchangeable. It lets the algorithm vary independently from clients that use it.
(a) Decorator
(b) Composite
(c) Strategy
(c) Strategy
Which method must be defined by a class implementing the java.lang.Runnable interface?
(a) public void start()
(b) void notify()
(c) void run()
(d) none of these
(c) void run()
wait(), notify() & notifyAll() are methods of which class or interface? (a) Object
(b) Thread class
(c) Runnable interface
(d) None
(a) Object
When start() method is called on thread it enters ______ state.
(a) running
(b) new
(c) waiting
(d) runnable
(d) runnable