Java OOPS Documentation
Java OOPS Documentation
What is OOPS?
Ans:
What is Class?
Ans:
What is Object?
Ans:
What is Encapsulation?
Ans:
What is Inheritance?
Ans:
Inheritance is process of acquiring methods and properties from one class to another
class.
Types:
- Single inheritance
- Multi-level Inheritance
- Multiple Inheritance
- Hierarchical Inheritance
- Hybrid Inheritance (mix-up of above all types)
Ans:
Abstraction in Java is a process of hiding the implementation details from the user
and showing only the functionality to the user.
What is Polymorphism?
Ans:
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).
Example
@Override
System.out.println("Dog barks.");
@Override
System.out.println("Cat meaw.");
}
Method Overloading
- If class has more than one method which has same name but different signature
it is called method overloading.
- Signature means,
o It can have different Return type
o It can have different parameters
o But Name should be same
Example
class Adder{
static int add(int a,int b){
return a+b;
}
static int add(int a,int b,int c){
return a+b+c;
}
static double add(double a, double b){
return a+b;
}
}
Ans:
- it is an object level variable like we gave reference name to array, List or our
user defined object.
Static Variable
- The static variable can be used to refer to the common property of all objects for
example, the company name of employees, college name of students
- The static variable are define inside class.
Local Variable
- A variable declared inside the body of the method or block is called local variable.
- A local variable cannot be defined with "static" keyword.
Why is the Java main method static?
Ans:
Ans:
Pass By Reference
- Jub bhi hum object create karte tab uska reference stack me store hota hai or
uski value heap store hoti hai.
- Agar me is object ko kisi method me pass karta hu to ek new reference create
hota hai jo same object ko point karta hai.
- Agar me iske through koi bhi changes object karta hu to vo changes original
me bhi hota hai.
Pass By Value
Final KeyWord
• Method
• Variable
- If you create any variable with final keyword then you can not change its
value.
• Class
- If you make any class as final, you cannot extend it.
autoboxing and unboxing feature convert primitives into objects and objects into
primitives automatically. The automatic conversion of primitive into an object is known as
autoboxing and vice-versa unboxing
Recursion in Java
- Recursion in java is a process in which a method calls itself continuously. A
method in java that calls itself is called recursive method.
Array
Array is a collection of similar type of elements which has contiguous memory location.
Super Keyword
The super keyword in Java is a reference variable which is used to refer immediate parent
class object.
Packages
Package in java can be categorized in two form, built-in package and user-defined
package.
1. Primitive data types: The primitive data types include boolean, char, byte, short, int,
long, float and double.
2. Non-primitive data types: The non-primitive data types include Classes, Interfaces,
and Arrays.