Interview Oops - Notes
Interview Oops - Notes
which contains some values, known as member data or member, and some set of rules,
known as behaviors or functions.
Eg:car template is created and multiple units of car are created based on the
template.
Objects
Eg:cat, dog
Inheritance
Inheritance allows us to define a class that inherits all the methods and
properties from another class.(child class inherits the data from parent class)
Parent class is the class being inherited from, also called base class.
Child class is the class that inherits from another class, also called derived class.
● Single Inheritance (only one super and subclass)--- child class inherits the data
from the parent class (mobile phone and sub is samsung ,redmi)
Polymorphism
It is of two types :
Eg:
Human Behaviour
Mobile phones
Encapsulation:
Encapsulation describes the concept of bundling data and methods within a single
unit.
School bag is one of the most real examples of Encapsulation. School bag can keep
our books, pens, etc. Realtime Example 2: When you log into your email accounts such
as Gmail, Yahoo Mail, or Rediff mail, there is a lot of internal processes taking place in
the backend and you have no control over it.
Abstraction:
ATM OPERATIONS - Because for example in atm machine --- We can use it for
withdrawal,retrieve mini receipt etc that is displaying relevant details and hiding
unnecessary details.
DATASTRUCTURES
Stack --- is a linear ds that is last in first out --undo /redo in excel
OOPS:
Class – A User-defined data type that holds data members and functions whose access
can be specified as private, public, or protected.
Eg:car
a car is an object. The car has attributes, such as weight and color, and methods, such
as drive and brake.
Objects
A dog is an object because it has states like color, name, breed, etc.
Inheritance
Inheritance allows us to define a class that inherits all the methods and
properties from another class.(child class inherits the data from parent class)
Parent class is the class being inherited from, also called base class.
Child class is the class that inherits from another class, also called derived class.
SI:
a sub-class is derived from only one super class. It inherits the properties and behavior
of a single-parent class. Sometimes it is also known as simple inheritance.
In the above figure, Employee is a parent class and Executive is a child class. The
Executive class inherits all the properties of the Employee class.
Multilevel
It is a chain of inheritance. As you can see the example below the CLass as box…weight
…shipment
ship> weight
weight>box
Or
When a class extends a class, which extends another class then this is called
multilevel inheritance. For example class C extends class B and class B extends
class A then this type of inheritance is known as multilevel inheritance.
Multiple
multiple inheritances the newly derived class can have more than one
superclass.
Hierarchical
When two or more classes inherit a single class, it is known as hierarchical inheritance.
In the example given below, Dog and Cat classes inherit the Animal class, so there is
hierarchical inheritance.
Hierarchial
If a number of classes are derived from a single base class, it is called hierarchical
inheritance.
Hybrid
Hybrid inheritance means consist of more than one.Hybrid is the combination of one or
types inheri
Polymorphism
Polymorphism in python defines methods in the child class that have the same
name as the methods in the parent class.
Human beviuour
For example, a person acts as an employee in the office, a customer in the shopping
mall, a passenger in bus/train, a student in school, and a son at home.
If a class has multiple methods having same name but different in parameters, it is known as
Method Overloading.
Encapsulation:
Encapsulation in Python describes the concept of bundling data and methods within
a single unit.
School bag is one of the most real examples of Encapsulation. School bag can keep
our books, pens, etc. Realtime Example 2: When you log into your email accounts such
as Gmail, Yahoo Mail, or Rediff mail, there is a lot of internal processes taking place in
the backend and you have no control over it.
Abstraction:
ATM OPERATIONS
Static method:
Static methods, much like class methods, are methods that are bound to a
class rather than its object. They do not require a class instance creation. So,
they are not dependent on the state of the object.
Static variable:
When we declare a variable inside a class, but outside the method, it is called a
static or class variable.
Method overriding -- runtime polymorphism. In this, the specific implementation of
the method that is already provided by the parent class is provided by the child
class. It is used to change the behavior of existing methods and there is a need
for at least two classes for method overriding. I
Method overloading
Friend Function:
a function that is given the same access as methods to private and protected
data.
Object overloading
Stack --- is a linear ds that is last in first out --undo /redo in excel
Linked lists - prev and next page in web browsers ---spotify playlist
Multithreading
EG:
Multiprocessing
multiprocessing is a package that supports spawning (that loads and executes new
module) processes using an API similar to the threading module.
Join keys
is used to combine rows from two or more tables, based on a related column
between them.
● (INNER) JOIN: Returns records that have matching values in both tables
● LEFT (OUTER) JOIN: Returns all records from the left table, and the
matched records from the right table
● RIGHT (OUTER) JOIN: Returns all records from the right table, and the
matched records from the left table
● FULL (OUTER) JOIN: Returns all records when there is a match in either
left or right table
Normalisation:
● Normalization is the process of organizing the data in the database.
2NF A relation will be in 2NF if it is in 1NF and all non-key attributes are fully
4NF A relation will be in 4NF if it is in Boyce Codd normal form and has no
multi-valued dependency.
Data Modelling is the process of analyzing the data objects and their relationship
to the other objects.
In Compile time Polymorphism, the call is resolved by the compiler. In Run time
Polymorphism, the call is not resolved by the compiler.
In Java static binding refers to the execution of a program where type of object is
determined/known at compile time i.e when compiler executes the code it know the type
of object or class to which object belongs. While in case of dynamic binding the type of
object is determined at runtime
In Java, an interface is a reference type similar to a class that can contain only
constants, the method signatures, default methods, and static methods, and its Nested
types.
Java Exception handling framework is used to handle runtime errors only. The
compile-time errors have to be fixed by the developer writing the code else the program
won't execute.
● Ensures the Continuity of the Program. ...
● Enhances the Robustness of the Program. ...
In the example, we are trying to divide a number by 0 . Here, this code generates an
exception. To handle the exception, we have put the code, 5 / 0 inside the try block.
Now when an exception occurs, the rest of the code inside the try block is skipped.
Here, Test() is a constructor. It has the same name as that of the class and doesn't have
a return type.
class Test {
Test() {
// constructor body
}
}
a keyword is a reserved word that conveys a specific meaning to the Java compiler
While--- entry control loop
Do while --- exit control loop
Class and objects
Inheritance -- single
Abstraction :
Polymorphism
class Bike{
1. void run(){System.out.println("running");}
2. }
3. class Splendor extends Bike{
4. void run(){System.out.println("running safely with 60km");}
5.
6. public static void main(String args[]){
7. Bike b = new Splendor();//upcasting
8. b.run();
9. }
10.}
encapsulation