POO Flashcards

1
Q

Characteristics of Object

A

Abstraction
Encapsulation
Message passing

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is abstraction ?

A

Abstraction: Abstraction is a process where you show only “relevant” data and “hide” unnecessary details of an object from the user

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is encapsulation ?

A

Encapsulation: Encapsulation simply means binding object state(fields) and behaviour(methods) together. If you are creating class, you are doing encapsulation.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is Message passing ?

A

A single object by itself may not be very useful. An application contains many objects. One object interacts with another object by invoking methods on that object. It is also referred to as Method Invocation.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Object Oriented Programming features

A

Abstraction , Encapsulation ,Inheritance ,Polymorphism

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

So what is the benefit of encapsulation in java programming

A

Well, at some point of time, if you want to change the implementation details of the class EmployeeCount, you can freely do so without affecting the classes that are using it.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Inheritance

A
The process by which one class acquires the properties and functionalities of another class is called inheritance. Inheritance provides the idea of reusability of code and each sub class defines only those features that are unique to it, rest of the features can be inherited from the parent class.
The biggest advantage of Inheritance is that the code in base class need not be rewritten in the child class.
 Multi-level inheritance is allowed in Java but not multiple inheritance
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Polymorphism

A

Polymorphism is a object oriented programming feature that allows us to perform a single action in different ways

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Types of Polymorphism

A

Static and dynamic

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Static Polymorphism

A

Polymorphism that is resolved during compiler time is known as static polymorphism. Method overloading can be considered as static polymorphism example.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Method Overloading

A

Method Overloading: This allows us to have more than one methods with same name in a class that differs in signature.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Dynamic Polymorphism

A
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 rather, thats why it is called runtime polymorphism.
Since both the classes, child class and parent class have the same method animalSound. Which of the method will be called is determined at runtime by JVM.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Abstract Class and methods in OOPs Concepts

A

Abstract method:
1) A method that is declared but not defined. Only method signature no body.
2) Declared using the abstract keyword
Used to put some kind of compulsion on the class who inherits the class has abstract methods. The class that inherits must provide the implementation of all the abstract methods of parent class else declare the subclass as abstract.
6) These cannot be abstract

Constructors
Static methods
Private methods
Methods that are declared “final”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Characteristics of Abstract

A

Note 2: Abstract class cannot be instantiated which means you cannot create the object of abstract class. To use this class, you need to create another class that extends this abstract class provides the implementation of abstract methods, then you can use the object of that child class to call non-abstract parent class methods as well as implemented methods(those that were abstract in parent but implemented in child class).

Note 3: If a child does not implement all the abstract methods of parent class(the abstract class), then the child class must need to be declared abstract.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Interfaces in Java

A

An interface is a blueprint of a class, which can be declared by using interface keyword. Interfaces can contain only constants and abstract methods (methods with only signatures no body).Like abstract classes, Interfaces cannot be instantiated, they can only be implemented by classes or extended by other interfaces. Interface is a common way to achieve full abstraction in Java.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Charcteristics of interface

A
All methods in an interface are implicitly public and abstract. Using the keyword abstract before each method is optional.
An interface may contain final variables.
When a class implements an interface it has to give the definition of all the abstract methods of interface, else it can be declared as abstract class
17
Q

Access Specifiers

A
There are four types of access specifiers in java:
public: Accessible to all. Other objects can also access this member variable or function.
private: Not accessible by other objects. Private members can be accessed only by the methods in the same class. Object accessible only in class in which they are declared.
protected: The scope of a protected variable is within the class which declares it and in the class which inherits from the class (Scope is class and subclass).
Default: Scope is Package Level. We do not need to explicitly mention default as when we do not mention any access specifier it is considered as default.
18
Q

Interfaces method default

A

Une méthode par défaut permet d’écrire une méthode dans une interface, en fixant sa signature et en donnant une implémentation.

Une classe concrète qui implémente une interface doit nécessairement fournir directement ou indirectement (dans une de ses super-classes) une implémentation pour toutes les méthodes abstraites de cette interface.

En revanche, si cette interface possède des méthodes par défaut, toute classe concrète qui l’implémente est libre de fournir sa propre implémentation de cette méthode par défaut, ou de ne rien faire. Dans ce cas, les instances de cette classe utiliseront l’implémentation par défaut fournie dans l’interface.

Ce mécanisme n’existe qu’à partir de Java 8. Jusqu’en Java 7 il n’est pas possible de créer des méthodes par défaut dans les interfaces.

19
Q

Interface Fonctionnelle

A

Cette définition mérite quelques commentaires.

Une unique méthode abstraite signifie qu’une interface fonctionnelle peut compter autant de méthodes statiques ou de méthodes par défaut que l’on veut. Et c’est bien le cas dans la pratique !

Les méthodes statiques et par défaut n’existent qu’à partir de Java 8. En Java 7 et avant, une interface fonctionnelle ne comporte donc qu’une unique méthode.

Les méthodes de la classe Object ne comptent pas dans ce total. Une interface fonctionnelle peut donc définir une première méthode abstraite a() et une seconde toString(). Pourquoi ? Tout simplement parce que tous les objets en Java étendent Object, donc on est sûr d’avoir une implémentation de ces méthodes dans les instances effectivement créées. En fait, si l’on déclare une méthode de la classe Object dans une interface, ce n’est pas pour garantir sa présence dans l’instance de cette interface, qui possédera de toute façon cette méthode, mais pour redéfinir la sémantique de cette méthode dans la Javadoc. C’est le cas par exemple dans la méthode equals(Object o), redéfinie dans l’interface Collection.

20
Q

Packages

A

A package as the name suggests is a pack(group) of classes, interfaces and other packages. In java we use packages to organize our classes and interfaces. We have two types of packages in Java: built-in packages and the packages we can create (also known as user defined package). In this guide we will learn what are packages, what are user-defined packages in java and how to use them.

21
Q

Types of packages

A

Types of packages in Java
As mentioned in the beginning of this guide that we have two types of packages in java.
1) User defined package: The package we create is called user-defined package.
2) Built-in package: The already defined package like java.io., java.lang. etc are known as built-in packages.

I have already discussed this above, let me mention it again here. If we create a class inside a package while importing another package then the package declaration should be the first statement, followed by package import.