oop with inheritance, polymorphisms ,encapsulation, and abstraction

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

Ways to achieve abstraction?

1)Abstract class (0 to 100%) 2)Interface (100%)

What is Abstraction?

1)Abstraction is a process of hiding the implementation details and showing only functionality to the user. 2)Abstraction lets you focus on what the object does instead of how it does it.

Advantages of Encapsulation

1)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. 2)It provides you the control over the data. 3)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. 4)The encapsulate class is easy to test. So, it is better for unit testing.

Terms used in Inheritance

1)Class: A class is a group of objects which have common properties. It is a template or blueprint from which objects are created. 2)Sub Class/Child Class: Subclass is a class which inherits the other class. It is also called a derived class, extended class, or child class. 3)Super Class/Parent Class: Superclass is the class from where a subclass inherits the features. It is also called a base class or a parent class. 4)Reusability: As the name specifies, reusability allows us to reuse the fields and methods of the existing class when you create a new class. You can use the same fields and methods already defined in the previous class.

Method Overriding

1)If subclass (child class) has the same method as declared in the parent class, it is known as method overriding in Java.

What is an Abstract Class?

A class which is declared as abstract Some points to remember : An abstract class must be declared with an abstract keyword. 1)It can have abstract and non-abstract methods. 2)It cannot be instantiated. 3)It can have constructors and static methods also. 4)It can have final methods which will force the subclass not to change the body of the method.

What is an abstract method?

A method which is declared as abstract and does not have implementation

Why multiple inheritance is not supported in Java?

To reduce the complexity and simplify the language, multiple inheritance is not supported in java.

Different ways to overload a method?

1)By changing number of arguments 2)By changing the data type

Polymorphism

1)the ability of an object to take on many forms 2)the most common use of polymorphism in oop occurs when a parent class reference is used to a child class object 3)any java object that can pass more than one IS-A test is considered to be polymorphic

What is encapsulation?

Encapsulation is a process of wrapping code and data together into a single unit. this can help create setter and getter methods in the class

Method Overloading vs Method Overriding

see next card

What is Generalization?

Generalization is the process of extracting shared characteristics from two or more classes, and combining them into a generalized superclass. Shared characteristics can be attributes, associations, or methods

method overloading

Method Overloading : 1)Method overloading is used to increase the readability of the program. 2)Method overloading is performed within class. 3)In case of method overloading, parameter must be different. 4)Method overloading is the example of compile time polymorphism. 5)In java, method overloading return type can be same or different in method overloading. But you must have to change the parameter.

Method Overriding

Method Overriding : 1)Method overriding is used to provide the specific implementation of the method that is already provided by its super class. 2)Method overriding occurs in two classes that have IS-A (inheritance) relationship. 3)In case of method overriding, parameter must be same. 4)Method overriding is the example of run time polymorphism. 5)Return type must be same or covariant in method overriding.

Can a static method be overridden?

No a static method cannot be overridden because the static method is bound with class whereas instance method is bound with an object.

Advantages of Inheritance

1)For Method Overriding (so runtime polymorphism can be achieved). 2)For Code Reusability

Method overloading

1)if a class has multiple methods having same name but different parameters. 2)If we have to perform only one operation, having same name of the methods increases the readability of the program.

What is inheritance?

Inheritance is where one object acquires all the properties and behaviors of a parent object. main purpose with inheritance is you can create new classes that are built upon existing classes. inheritance represents the IS-A relationship which is also known as a parent child relationship

Types Of Inheritance In Java

On the basis of class, there can be three types of inheritance in java: single, multilevel and hierarchical.

What is Specialization?

Specialization means creating new subclasses from an existing class. If it turns out that certain attributes, associations, or methods only apply to some of the objects of the class, a subclass can be created.

Access Modifiers

They are keywords that control the ability for outside code to access or change the states and behaviors of a class.There are 4 types of java access modifiers: private default protected public

Usage and rules for method overiding

Usage: 1)Method overriding is used to provide the specific implementation of a method which is already provided by its superclass. 2)Method overriding is used for runtime polymorphism Rules: 1)The method must have the same name as in the parent class 2)The method must have the same parameter as in the parent class. 3)There must be an IS-A relationship (inheritance)


संबंधित स्टडी सेट्स

Cells, mitosis, review of POB lecture quiz

View Set

Sigmon- Earth & Enviromental Science Final Exam Review

View Set

left + right sided heart failure

View Set

PreAlgebra: sections 5-5 to 5-9 Vocab

View Set

Social psychology - Prosocial behavior and altruism Ch 11

View Set