OOP Flashcards
What Is OOP
a type of computer programming (software design) in which programmers define not only the data type of a data structure, but also the types
of operations (functions) that can be applied to the data structure.
In this way, the data structure becomes an object that includes both data and functions. In addition, programmers can create relationships between one object and another. For example,
objects can inherit characteristics from other objects.
What are the advantages of OOP
-Code Reuse
-Encapsulation
-Design benefits as easier to program due to extensive planning phase at beginning
-Software maintenance is easy
What is encapsulation
a programming language construct that facilitates the bundling of data with the
methods (or other functions) operating on that data.
Encapsulation is an OOP concept where object state(class fields) and it’s behavior(methods) is
wrapped together. Java provides encapsulation using class.
What are the benefits of encapsulation
-you can use a method without knowing how it works. Once an
Object is created
-hide certain parts of themselves from
programmers. This prevents progrmers from tampering with values they
shouldn’t.
-object controls how one interacts with it, preventing
other kinds of errors.
What is a class
a construct that is used to define a distinct new type and is made up of
properties (attributes) that are grouped together to describe the object and
functions and procedures (methods/behaviour) that describes what the object can do.
What other words can be used to describe a class
-a building plan for a house
-a template
-a blueprint
What does the first part of a UML diagram show
properties/ fields of class with their data types – describe what object “looks
like”
What does the second part of a UML diagram show
methods
What does the + access modifier mean
accessible from outside class in any other class
What does the - access modifier mean
NOT accessible from outside class
What does the access modifier protected mean
only accesible in child class that inherits from parent class.
What is an object
a dynamic instance of a class.
How is an object instantiated
Using the constructor
What is a constructor
code in a special method that
will create the object in memory while the program is running.
What a the relationship between objects and classes
Many objects can be created
from the same class. Just like you can declare many variables of the same type, you can have
many instances of your class as objects in one application Each object can have its own values
What is information hiding
a programming language mechanism for restricting access to some of the
object’s components. When fields and methods are declared under private in the class, it is only
visible in the object itself. These private variables and methods are protected against
unintentional modification.
How can you access private variables
by using typed methods to
get the values and make it available to the unit where the object is used.(getters)
How do you change private variables
by using void methods to
set values.(setters)
What are the constructor, accessor and mutator methods set as
The Constructor, Accessor methods and Mutator methods must be declared as public so
that other units can use them.
How do you determine the name of a constructor
The name of a constructor must be the same name as the class
Is it possible to have more than one constructor
Yes !
Like a no argument constructor which is the default constructor etc
What is an argument list
The parameters of the constructor (The variables in the brackets next to the constructor )
What are the two types of constructors
Parameterised constructor and default constructor
What is a parameterised constructor
You can provide your constructor with parameters to
initialise fields to values of your choice each time the constructor is called