OOP QC Question Bank

¡Supera tus tareas y exámenes ahora con Quizwiz!

Define Abstraction and provide advantages to using it

-Abstraction is a process of hiding the implementation details and showing only functionality to the user. -Another way, it shows only essential things to the user and hides the internal details, for example, sending SMS where you type the text and send the message. You don't know the internal processing about the message delivery. -Abstraction lets you focus on what the object does instead of how it does it. -Abstraction occurs when you simplify a complex thought or complex system

Define Encapsulation and provide advantages to using it

-Encapsulation is the process of enclosing an item inside of a capsule or container -In software development, encapsulation refers to the act of protecting data members from outside influence -Encapsulation is a way of "data hiding" if access modifier is private -The process of data restriction -Encapsulation in Java is a process of wrapping code and data together into a single unit, for example, a capsule which is mixed of several medicines. We can create a fully encapsulated class in Java by making all the data members of the class private. Now we can use setter and getter methods to set and get the data in it -The Java Bean class is the example of a fully encapsulated class -Ex. In computing based on the Java Platform, JavaBeans are classes that encapsulate many objects into a single object. They are serializable, have a zero-argument constructor, and allow access to properties using getter and setter methods. - Having a method call another method Advantages -By providing only a setter or getter method, you can make the class read-only or write-only. In other words, you can skip the getter or setter methods. -It provides you the control over the data. Suppose you want to set the value of id which should be greater than 100 only, you can write the logic inside the setter method. You can write the logic not to store the negative numbers in the setter methods. -It is a way to achieve data hiding in Java because other class will not be able to access the data through the private data members. -The encapsulate class is easy to test. So, it is better for unit testing

Define Inheritance and provide advantages to using it

-Inheritance in Java is the process by which one object acquires all the properties and behaviors of a parent object. -The idea behind inheritance in Java is that you can create new classes that are built upon existing classes. When you inherit from an existing class, you can reuse methods and fields of the parent class. Moreover, you can add new methods and fields in your current class also. -Inheritance represents the IS-A relationship which is also known as a parent-child relationship. NOTE: A CLASS IN JAVA CAN ONLY EXTEND ONE OTHER CLASS (remember, multiple inheritance not supported in Java) -SYNTAX: The extends keyword indicates that you are making a new class that derives from an existing class. The meaning of "extends" is to increase the functionality. -On the basis of class, there can be three types of inheritance in java: single, multilevel and hierarchical. -In java programming, multiple and hybrid inheritance is supported through interface only. Advantages of Inheritance -For Method Overriding (so runtime polymorphism can be achieved). -Allows For Code Reusability.

Describe the characteristics of the object-oriented paradigm

-OOP refers to a programming methodology based on objects, instead of just functions and procedures. These objects are organized into classes, which allow individual objects to be grouped together -OOPs makes it easier to manage if code grows as project size increases. -OOPs provides data hiding whereas in a procedure-oriented programming language a global data can be accessed from anywhere.

Define Polymorphism and provide advantages to using it

-Polymorphism is the ability of an object to take on many forms. The most common use of polymorphism in OOP occurs when a parent class reference is used to refer to a child class object. -Any Java object that can pass more than one IS-A test is considered to be polymorphic. In Java, all Java objects are polymorphic since any object will pass the IS-A test for their own type and for the class Object. -An important example of polymorphism is how a parent class refers to a child class object. In fact, any object that satisfies more than one IS-A relationship is polymorphic in nature. For instance, let's consider a class Animal and let Cat be a subclass of Animal. So, any cat IS animal. Here, Cat satisfies the IS-A relationship for its own type as well as its super class Animal.

What are some different inheritance strategies?

H

Pillars of OOP

Inheritance Polymorphism Encapsulation Abstraction

What is parametric polymorphism?

J

What is ad hoc polymorphism?

K

What is the difference between class-based inheritance and prototypal inheritance?

L

What does the acronym SOLID stand for?

M

Describe the Single Responsibility Principal

N

Describe the Open/Closed Principal

O

Describe the Liskov Substitution Principal

P

Describe the Interface Segregation Principal

Q

Describe the Dependency Inversion Principal

R

What is the DRY Principal?

S

What are some different types of polymorphism?

There are two types of polymorphism in java: 1) Static Polymorphism also known as compile time polymorphism 2) Dynamic Polymorphism also known as runtime polymorphism Compile time Polymorphism (or Static polymorphism) Polymorphism that is resolved during compiler time is known as static polymorphism. Method overloading is an example of compile time polymorphism. Method Overloading: This allows us to have more than one method having the same name, if the parameters of methods are different in number, sequence and data types of parameters Example of static Polymorphism Method overloading is one of the way java supports static polymorphism. Here we have two definitions of the same method add() which add method would be called is determined by the parameter list at the compile time. That is the reason this is also known as compile time polymorphism. class SimpleCalculator { int add(int a, int b) { return a+b; } int add(int a, int b, int c { return a+b+c; } } public class Demo { public static void main(String args[]) { SimpleCalculator obj = new SimpleCalculator(); System.out.println(obj.add(10, 20)); System.out.println(obj.add(10, 20, 30)); } } Output: 30 60 Runtime Polymorphism (or Dynamic polymorphism) It is also known as Dynamic Method Dispatch. Dynamic polymorphism is a process in which a call to an overridden method is resolved at runtime, thats why it is called runtime polymorphism. Example In this example we have two classes ABC and XYZ. ABC is a parent class and XYZ is a child class. The child class is overriding the method myMethod() of parent class. In this example we have child class object assigned to the parent class reference so in order to determine which method would be called, the type of the object would be determined at run-time. It is the type of object that determines which version of the method would be called (not the type of reference).

What is sub-type polymorphism?

o


Conjuntos de estudio relacionados

Cost Accounting Exam #1 (Ch. 1-3, 5, 6, 16)

View Set

Survey of U.S. History - Exam One Study Guide

View Set

Marriage, Families and Relationships Module 3

View Set

Ansley Bonus Ch. 7-8 (Surface Tension Lab, Chromatography Lab, Water Video)

View Set

Medical Insurance & Billing Ch.9

View Set