• Barajar
    Activar
    Desactivar
  • Alphabetizar
    Activar
    Desactivar
  • Frente Primero
    Activar
    Desactivar
  • Ambos lados
    Activar
    Desactivar
  • Leer
    Activar
    Desactivar
Leyendo...
Frente

Cómo estudiar sus tarjetas

Teclas de Derecha/Izquierda: Navegar entre tarjetas.tecla derechatecla izquierda

Teclas Arriba/Abajo: Colvea la carta entre frente y dorso.tecla abajotecla arriba

Tecla H: Muestra pista (3er lado).tecla h

Tecla N: Lea el texto en voz.tecla n

image

Boton play

image

Boton play

image

Progreso

1/29

Click para voltear

29 Cartas en este set

  • Frente
  • Atrás
What is OOPS?
* Object-Oriented Programming is a Programming Paradigm based on the concept of "objects", which may contain data (fields or attributes) and functionalities(methods).
* In an object-oriented approach, requirements are organized around objects, which integrate both data and functions.
* They are modeled after real-world objects that the system interacts with.
What are the advantages of OOPS concepts?
* Simplicity: OOPS programming objects model real-world objects, so the complexity is reduced and the program structure is clear.
* Modularity: Each object forms a separate entity whose internal workings are decoupled from other parts of the system.
* Modifiability: It is easy to make minor changes in the data representation or the procedures in an OO program. Changes inside a class do not affect any other part of a program, since the only public interface that the external world has to a class is through the use of methods.
* Extensibility: Adding new features or responding to changing operating environments can be solved by introducing a few new objects and modifying some existing ones.
* Maintainability: Objects can be maintained separately, making locating and fixing problems easier.
* Reusability: Objects can be reused in different programs.
What is the difference between Procedural programming and OOPS?
* Procedural language is based on functions but object-oriented language is based on real-world objects.
* Procedural language gives importance to the sequence of function execution but object-oriented language gives importance to the states and behaviors of the objects.
* Procedural language exposes the data to the entire program but object-oriented language encapsulates the data.
* Procedural language follows a top-down programming paradigm but object-oriented language follows a bottom-up programming paradigm.
* Procedural language is complex in nature so it is difficult to modify, extend and maintain but object-oriented language is less complex in nature so it is easier to modify, extend and maintain.
* Procedural language provides less scope of code reuse but object-oriented language provides more scope of code reuse.
What is a Class?
* A class is the specification or template of an object.
What is an Object?
An object is an instance of a class.
What are the core concepts of OOPS?
* Abstraction
* Encapsulation
* Polymorphism
* Inheritance
* Association
* Aggregation
* Composition
Abstraction
Construct the structure of the real-world objects, taking the most abstract states and behaviors.
Encapsulation
Create and define the permissions and restrictions of an object and its member variables and methods through visibility and modifiers.
Polymorphism
Polymorphism is the occurrence of something in various forms. Java supports various forms of polymorphism like:
*Polymorphic reference variables -> Class A extends B ==> A instanceOfA = new B();
*Polymorphic method -> Method overloading and Method Overriding.
*Polymorphic return types -> public List returnListMethod() {... return new ArrayList<>();}
*Polymorphic argument types -> public void argumentListMethod(List<> list) { ... }; argumentListMethod(new ArrayList<>());
Inheritance
A subclass can inherit the states and behaviors of its superclass. A child class inheriting states and behaviors from multiple parent classes is known as multiple inheritances. Java doesn't support it.
Association
Is a relationship between two objects with multiplicity.
Aggregation
Is a special form of association.
* Is "weak containment" and it's a directional association.
* The objects have their own life-cycle but there exists ownership as well.
* If the parent object is destroyed, the child objects would still exist.
*Is a typical whole/part relationship
*Is also known as "HAS-A" relationship.
Composition
Is a specialized form of aggregation.
*Is actually a strong type of aggregation and is also referred to as a "death" relationship.
*Is a "strong containment" relationship.
*If the parent object is destroyed, the child objects would cease to exist.
What is the difference between Association and Dependency?
* Association to represent something like a field in a class.
* A dependency exists between two elements if changes to the definition of one element (the supplier) may cause changes to the other (the client).
*Associations also imply dependency, if there is an association between two classes, there is also a dependency.
What is the meaning of the "IS-A" and "HAS-A" relationship?
* "IS-A" relationship implies inheritance. A sub-class object is said to have an "IS-A" relationship with the superclass or interface.
* If class A extends B then A "IS-A" B.
* It is transitive, that is, if class A extends B and class B extends C then A "IS-A" C.
* The "instanceof" operator in Java determines the "IS-A" relationship.
* When class A has a member reference variable of type B then A "HAS-A" B.
* "HAS-A" It is also known as Aggregation.
What are Static Binding and Dynamic Binding?
* Static or early binding is resolved at compile time.
* Method overloading is an example of static binding.
* Dynamic or late or virtual binding is resolved at run time.
* Method overriding is an example of dynamic binding.
What is the method hiding in Java?
* When you declare two static methods with the same name and signature in both superclass and subclass then they hide each other.
* i.e. a call to the method in the subclass will call the static method declared in that class and a call to the same method is superclass is resolved to the static method declared in the super class.
Can we overload a static method in Java?
* Yes, as long as they have different signatures.
Can we override the static method in Java?
* No, you cannot override a static method because it's not bounded to an object.
Can we override a private method in Java?
* Only from inner classes, and not subclasses.
What is covariant method overriding in Java?
* The overriding method can return the subclass of the object returned by original or overridden method.
* e.g. Object#clone() [returns Object]; can be overridden and subclassed by Date#clone() [Returns Date];
* Is a type of polymorphism.
Can we override a method that throws runtime exception without a throws clause?
* Yes, there is no restriction on unchecked exceptions while overriding.
* However, in checked exceptions, an overriding exception cannot throw a checked exception which comes higher in the type hierarchy
* e.g. if the original method is throwing IOException then the overriding method cannot throw java.lang.Exception or java.lang.Throwable.
How do you call a superclass version of an overriding method in a sub-class?
* super.method().
* e.g.
@Override
public String toString() {
return super.toString();
}
Can we have a non-abstract method inside the interface?
Only from Java 8 onwards, there can be a default method.
What is the default method of Java 8?
* This method has implementation and is intended to be used by default.
* By using this method, JDK 8 managed to provide common functionality related to functional interfaces.
Can we make a class both final and abstract at the same time?
* No, they are exactly opposite of each other.
* A final class cannot be extended.
* You cannot use an abstract class without extending and making it a concrete class.
Can we overload or override the main method in Java?
* No, since main() is a static method, you can only overload it.
What is the difference between Composition and Inheritance in OOP?
* Composition allows the class to get an additional feature at runtime, but Inheritance is static.
* You can not change the feature at runtime by substituting a new implementation.
Why favor Composition over Inheritance?
* Static vs Dynamic -> It cannot be changed at runtime, but with Composition, you just define a Type which you want to use, which can hold its different implementation.
* Limited code reuse with Inheritance -> with Inheritance you can only extend one class, which means your code can only reuse just one class.
* Unit Testing -> Using Composition they are easier to test because you can supply a mock implementation of the classes you are using. There is no way you can provide a mock implementation of the parent class.
* Final classes -> Composition allows code reuse even from final classes, which is not possible using Inheritance.
* Encapsulation -> Inheritance breaks encapsulation because a sub-class is dependent upon super class behavior. If parent classes change their behavior then child class is also get affected.