OOP - Object Oriented Programming Flashcards
What are six core concepts of Object Oriented Programming
Objects, Classes, Inheritance, Polymorphism, Abstraction, Encapsulation
An entity that has a state & behavior, and can be physical or logical
Object
An object can be defined as an instance of a _____
Class
What can objects do without knowing the details of each other’s data or code?
Communicate
What is necessary for objects to communicate?
The type of message accepted and the type of response returned
Java classes define what two things relating to objects?
Data types and methods
A class can be defined as a ____ from which you can create an individual object.
Blueprint
Do classes consume space?
No
What are two advantages of Object Oriented Programming compared to Procedure Oriented Programming?
Easier development & maintenance (including when upscaling), Data hiding
A Java constructor is a block of code similar to what?
The method
What Java entity is called when an instance of an object is created and memory is allocated for the object?
A constructor
A Java constructor is a special type of method which is used to do what?
Initialize the object
When an object is created, the compiler makes sure that constructors for all of its ____ are called.
Subobjects (member & inherited objects)
What must members have for constructors to be called automatically when an object is created?
Default constructors / constructors without parameters
What can be done when an object is created but members do not have default constructors or constructors without parameters?
Parameterized constructors can be called using an initializer list
Why do constructors have this name?
Because they construct values at the time of object creation
Does the Java compiler create a default constructor if your class doesn’t have any?
Yes
One of three rules defined for the constructor is that the constructor name must be the same as ____.
Its class name
One of three rules defined for the constructor is that a constructor must have no explicit ____.
Return type
One of three rules defined for the constructor is that a Java constructor cannot be what three things?
Abstract, static/final, asynchronized
What are the two types of constructors?
Default and parameterized
The default constructor is a ____ constructor that the Java compiler inserts on your behalf.
No-argument
What is the (default) behavior of the default constructor?
It contains a “default” call to super();
If you implement any constructor, will you continue to receive a default constructor?
No
What is a parameterized constructor used for?
To provide different values to distinct objects
In Java, a constructor is just like a method but without what?
A return type
What is the technique in Java of having multiple constructors with different parameter lists?
Constructor overloading
How are constructors arranged in constructor overloading?
Such that they perform different tasks
How does the compiler differentiate constructors in constructor overloading?
By the number & types of parameters
Is a constructor or a method used to intialize the state of an object?
Constructor
Is a constructor or a method used to expose the behavior of an object?
Method
Must or must not a constructor have a return type?
Must not
Must or must not a method have a return type?
Must
Is a constructor invoked explicitly or implicitly?
Implicity
Is a method invoked explicitly or implicitly?
Explicitly
Does the Java compiler provide a constructor if one is not already present?
Yes
Does the compiler provide a method?
No
Must the constructor name be the same as the class name?
Yes
Must the method name be the same as the class name?
No
What is a mechanism in Java in which one object acquires all the properties & behaviors of a parent object?
Inheritance
What is the basic premise behind inheritance?
To create new classes that are built upon existing ones.
When inheriting from an existing class, what two things can be reused from the parent?
Methods and fields
Can you add new methods and fields to the child class during inheritance?
Yes
What is another name for the parent-child relationship that inheritance represents?
IS-A relationship
What are two advantages of inheritance?
Method overloading (for runtime polymorphism), and code reusability
What are three other names for the child class?
Sub class, derived class, extended class
What are two other names for the parent class?
Super class, base class
What keyword in the code indicates the creation of a new class that derives from an existing class?
Extends
What are the three basic types of inheritance in Java?
Single, multilevel, hierarchical
What are the two types of inheritance only supported through the interface?
Multiple, hybrid
Why is multiple inheritance not supported in Java?
To reduce complexity and simplify the language
Does multiple inheritance cause Java render a runtime error or a compile-time error?
Compile-time error
What term refers to the ability of an object to take on many forms?
Polymorphism
What is the most common use of polymorphism in OOP?
When a parent class reference is used to refer to a child class object
What term describes if a class has multiple methods with the same name but different parameters?
Method overloading
What are the two ways to overload a method in Java?
Changing the number of arguments, changing the data type of the arguments
Can you overload the main method in Java?
Yes
What term in Java describes if a child class has the same method as declared in the parent class?
Method overriding
One usage of method overriding is to provide specific implementation of ____ which is already provided by its parent class.
A method
One usage of method overriding is ____
Runtime polymorphism
In method overriding, the method must have the same ____ and ____as its parent class.
Name, parameter
What relationship must be present in method overriding?
IS-A relationship (inheritance)
Why can’t a static method be overridden?
It is bound with a class (whereas an instance method is bound with an object)
Is method overloading or overriding used to increase the readability of the program?
Overloading
Is method overloading or overriding performed within a class?
Overloading
Does method overloading or overriding occur in two classes with an inheritance relationship?
Overriding
In method overloading, must the parameter be different or the same?
Different
In method overriding, must the parameter be different or the same?
The same
Is method overloading an example of compile time or run time polymorphism?
Compile time polymorphism
Is method overriding an example of compile time or runtime polymorphism?
Runtime polymorphism
Between method overloading and overriding, in which does it not matter if the return type is the same or different?
Overloading
Between method overloading and overriding, in which must the return type be the same or covariant?
Overriding
What is the process in Java of wrapping code and data together into a single unit, for example, a bottle which contains several mixed medicines?
Encapsulation
How can a fully encapsulated class in Java be created?
By making all the data members of the class private
What is the “Java Bean” class an example of?
A fully encapsulated class
What can be done to make an encapsulated class read-only or write-only?
Provide only a getter or setter method
What are the two types of modifiers in Java?
Access and non-access
The access modifier in Java specifies the accessibility (scope) of any of what four things?
Data member, method, constructor, class
What are the four types of Java access modifiers?
Private, default, protected, public
Which access modifiers can be applied within a class?
Public, private, default, protected
Which access modifiers can be applied within a package?
Default, protected, public
Which access modifiers can be applied outside a package by a subclass?
Protected, public
Which access modifier can always be applied outside a package?
Public
What is the process of hiding the implementation details and showing only functionality to the user?
Abstraction
What is the process of extracting shared characteristics from two or more classes, and combining them into a generalized superclass?
Generalization
What are the three applicable shared characteristics in generalization?
Attributes, associations, methods
If certain attributes, associations, or methods only apply to some of the objects in a class, what is the process of creating new subclasses from an existing class?
Specialization
What are the two ways to achieve abstraction?
Abstract class (0 to 100%), Interface (100%)
Can an abstract class have non-abstract methods?
Yes
An abstract class needs to be ____ and its method needs to be ____
Extended, implemented
Can an abstract class be instantiated?
No
How must an abstract class be declared?
With the abstract keyword
Can an abstract class have constructors? Can it have static methods?
Yes, yes
Abstract classes can have final methods which will do what?
Prevent the subclass from changing the body of the method