MOOC Part 9 Flashcards
Why does every class in java have the built in methods methods toString, equals, and hashCode?
Every java class inherits the Object class.
What is the concept of polymorphism?
The capability of a method to do different things based on the object that it is acting upon. In other words, polymorphism allows you define one interface and have multiple implementations.
What are the two types of polymorphism?
Compile time which uses method overloading, functions can be overloaded by the change in the number of arguments.
Run time uses method overriding, in which the subclass provides a definition to a method already present in the superclass, then that function in the base class is overridden.
What is the concept of inheritance?
A process in which one class (subclass) acquires the properties (methods and fields) of another class (superclass).
What keyword is used to to inherit the properties of a class?
extends
What is the protected access modifier?
Open to use by its subclasses and the class it was defined in
What is the Single Responsibility Principle?
Each class should only have one responsibility, thus one reason to change. It reduces the probability and complexity of class changes as it reduces the number of dependent classes affect by changes.
What is an interface and its purpose?
A container that stores the specification of method protoypes, allows the specification of methods and fields through only names, parameters and return values, does not have a say on the internal implementation. Also allows for multiple inheritence.
Futhermore, it reducing dependacies between classes.