OOPs - Class, Object, Methods in java

 Object Oriented Programming System/ Structure

OOPs is a programing paradigm/ methodology. (Paradigm - method to solve some problem ).

Types of paradigm

  1.  Object oriented paradigm
  2. procedural paradigm
  3. functional paradigm
  4. logical paradigm
  5. structural paradigm.
Piller of OOPs
  1. class
  2. Object and method
  3. inheritance
  4. Abstraction
  5. Polymorphism
  6. Encapsulation
Class and Object - 
  1. Class is a collection of Object.
  2. Class is a template / class is a blueprint of object, it not a real entity ( animal is not real but dog is real )
Syntax - 

access-modifier class ClassName{
	- methods
    - constructors
    - fields
    - blocks
    - nested class
}
Methods - set of code perform a particular task. ( uses - code resusability, code optimization )
Syntax - 
access-modifier return-type methodName(list of Parameter){}
Object - 
  1. is an instance of class 
  2.  it is real world entity ( dog, cat ).
  3. it occupies memory. 
object consist of - ( ex Dog)
  1. Identity - name
  2. state / Attribute ( color, bread, age )
  3. Behavior - ( eat, run )
HOw to create Object
  1. using new keyword.
  2. newInstance() method ( it is predefined method)
  3. clone ( ) method
  4. deserialization method 
  5. Factory method
Syntax - 
Animal tommy;    //declaration method
tommy = new;     // instantiation method
tommy = new Animal()  // initialisation 
Animal tommy = new Animal()
How to call method though object -
tommy.run()
Example
class Animal
{
	public void eat(){
    	System.out.println("i am eating");
    }
    public static void main(String [] arg){    	
    	Animal tommy = new Animal();   // object
        tommy.eat();
    }
}
How to initialize object
- by reference Veriable - 
class Animal  // No access modifier so it take default{
	String color;
    int age;
    public static void main(String [] age){
    	Animal tommy = new Animal();
        tommy.color = "black";
        tommy.age = 10;
        System.out.println(tommy.color +" " + tommy.age );
    }
}
- by using Method - 

class Animal  // No access modifier so it take default{
	String color;
    int age;
    public static void main(String [] age){
    	
        void dogInfo(String color, int age ) {
        	color = color;
            age = age;
        }
        void display(){
        	System.out.print(Color + " " + age);
        }
        
    	Animal tommy = new Animal();
        tommy.dogInfo("black", 10);
        tommy.display();       
    }
}