-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.java
More file actions
34 lines (33 loc) · 913 Bytes
/
example.java
File metadata and controls
34 lines (33 loc) · 913 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
class employee{
int ID;
String name;
double salary;
void initDetails(int id, String n, double s){
//This function works as a constructor
ID = id;
name = n;
salary = s;
}
employee(int ID, String name, double salary){
//No return type for contructor
//parameterised constructor
//default constructor is parameterless constructor
this.ID = ID;
this.name = name;
this.salary = salary;
}
void printDetails(){
System.out.println("ID :"+ID);
System.out.println("Name :"+name);
System.out.println("Salary :"+salary);
}
}
class example{
public static void main(String args[]){
employee e1 = new employee(1234,"Manan",20000000);
employee e2 = new employee(1235,"Sanjay",200000);
//e1.initDetails(1234,"Sanjay",20000);
e1.printDetails();
e2.printDetails();
}
}