General Object-Oriented Programming Flashcards
What is a class?
grouping of variables and methods in a source code file, from which objects can be created. Class is a grouping of variables and methods in a source code file that acts as a template/ blueprint for creating objects
What is an interface?
defines methods and holds a group of abstract methods and properties, is used to specify a behavior that classes must implement. ex appliances can all plug into a power outlet
What is encapsulation?
binds data and it’s related methods together within a class. It also protects the data by making fields private and giving access to them only through their related methods ex) bank account
What is inheritance?
when one class adopt the properties and methods of another class ex) dog and duck are both animals, both make sound and movement but differently
What is polymorphism?
the ability of an object to take on many forms ex) woman is a sister, friend, employee
***Why would you use an interface instead of inheritance?
you can inherit many interfaces, but only one base class ex) base discount, birthday discount, military discount)
What’s the difference between a class and an interface?
A class describes the attributes and behaviors of an object. An interface contains behaviors that a class implements. A class may contain abstract methods, concrete methods. An interface contains only abstract methods.
What’s the difference between a class and an object?
Class is a template or blueprint to a house, object is an instance of a class, has their own data, the object is the house
Give me an example of where you might want to apply inheritance
Horse, Dog, Elephant inherits from animal
Give me an example of where you might want to apply interfaces
two classes for an alarm, one is a phone and one is an alarm clock but they can both be used for alarms or applicances can do different things but all are able to plug into a wall outlet
What is an abstract class?
a restricted class that “shows” only essential attributes and “hides” unnecessary information, cannot be used to create objects ex) travel abstract class is country and can use an interface to say iFlyable or iTrainable
What is a static method?
a method that only belongs that one class which prevents inheritance, is not stored
What is an Array?
collection of elements of the same type, can be individually referenced by using an index to a unique identifier, length cannot be changed
What is a static class?
a class that cannot be instantiated
define refactoring
allows you to change the code structure without changing or affecting what the code itself actually does// making changes to the code without changing its function, like changing parameter or variable names ex change var name from name to firstName to be more descriptive and differentiate between first, middle and last name