Class is logical construct and objects are Physical reality
Objecta are categorised by state,identity,behaviour.
Object are created in heap memory and variables in stack .
Student student = new Student();
------------------- ---------------
Complile time. Runtime
A special function that runs when we create a object and it allocates some variables. Allocate values that we need when creation of objects.
access the reference variable of object
cannot use inside static blocks.
a constructor without argument is acually a default constructor.
Same as function overloading
We can call a constructor inside another constructor using the this keyword.
Integer num =45
it is now created as object
When we pass objects reference values are passed.
final int INCREASE = 2;
always initialise when using final keyword
`final Student akshay = new Student();
when a non primitive is final we cannot reassign it but we can change the values.
finalise method
Distructing ..java executes this method before garbage collection.sort of like a clean up method.
@Override
protected void finalise() throws Throwable {
System.out.println(" Object is distroyed ");
}
properties common to all the object of a class
To acess static variable inside constructor we use Class name
Outside class cannot be static
inner class can be static
Just a class that we can create only one object of
public class Singleton{
private Singleton(){
private Singleton instance;
public static Singleton getInstance(){
if(instance == null){
instance = new Singleton():
}
}
}
super () used to initialise values in parent class.
Types of Inheritance
Single Inhertance : one class extends another class.
Multilevel Inheritance : java doesnt support
Hierachical Inhertance
Hibrid Inheritance - Combination of single and multiple inheritance
Compile Time or static polymorphishm --- bY METHOD OVERLOADING
Runtime or Dynamic polymorphism ----by method overiding. @Override keyword
CHILD CLASS OVERRIDES PARENT METHOD
Interfaces
You can inherit but you cant override static methods
wrapping up implemention of data members & methods in a class
Hiding unnessasary details and showing valuable information.
Data Hiding