OOPS Java Flashcards
abstract classes
provide complete, default code and/or just details that have to be overriden. only extends 1. can have non-abstract methods, constructors, instance variables, or public,private,protected. fast. more for reusability
interfaces
cannot provide code only signature, implement several interfaces. all methods are abstracts. only public or none members. only static/final variables. slower. methods must be public. for implementing functionality
what is polymorphism
“as one interface, many implementations”. a characteristic of being able to assign a different meaning or usage to something in different contexts
runtime polymorphism/dynamic method dispatch
a process in which a call to an overridden method is resolved at runtime rather than compile-time. an overridden method is called through the reference variable of a superclass. determination of the method to be called is based on the object being referred to by the reference variable.
method overloading
methods of same class shares same name, but each method has dif parameters or dif signatures. compile time polymorphism.
method overriding
subclass have same method with same name and exactly same signature. to change existing behavior of method in inheritance. run time polymorphism. DOESN’T WORK IF PARENT HAS STATIC
can you override private or static method?
no since is not visible from other class. if you create similar method with same signature in child class then it’ll hide super class method (method hiding)
multiple inheritance
where child class inherits property from multiple classes. problem with it is that if multiple parent classes have same method name, then at runtime it becomes difficult for compiler to decide which method to execute from child class. JAVA MULTIPLE INHERITANCE NOT SUPPORTED.
instantiate
creates object with new
initialization
new with constructor initializes new object
instantiate new object with new parameters
calls all constructors from down up