Java : Class object creation

This is about to provide the real time developments notes .

Java:

1.How to write a class

class Employee{
int id;     //for employee id
String name;    //for employee name


}


2. How to create a object of class
 i.e
Employee emp=new Employee();
Note emp is an object of class employee.

3.How to write a method in class
i.e;
Class Employee {

public  void m1()   //m1 method has written
{
//logic 
}

}

4. How to call a method

Fisrt create the object .
then call the method as follow
emp.m1();

5. Example :complete example
------------------------------------------------------------------
class employee
{
int id;
String name;
 employee(int id,String name){
id=this.id;
name=this.name; //
}
public void m1(){
system.out.println(" hello m1 method  calling ") ;
}
}
//object creation and parameter calling
Employee emp=new Employee();

 ---------------------------------------------------------------





Comments

Popular posts from this blog

Angular 2 & 2+

How spring flow

database logic