Skip to content

Commit d141dee

Browse files
Custom Class
1 parent 6bcd0ca commit d141dee

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed
+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
class Employee{
2+
int id;
3+
int salary;
4+
String name;
5+
public void printDetails(){
6+
System.out.println("My id is " + id);
7+
System.out.println("and my name is "+ name);
8+
}
9+
10+
public int getSalary(){
11+
return salary;
12+
}
13+
}
14+
15+
public class cwh_38_custom_class {
16+
public static void main(String[] args) {
17+
System.out.println("This is our custom class");
18+
Employee harry = new Employee(); // Instantiating a new Employee Object
19+
Employee john = new Employee(); // Instantiating a new Employee Object
20+
21+
// Setting Attributes for Harry
22+
harry.id = 12;
23+
harry.salary = 34;
24+
harry.name = "CodeWithHarry";
25+
26+
// Setting Attributes for John
27+
john.id = 17;
28+
john.salary = 12;
29+
john.name = "John Khandelwal";
30+
31+
// Printing the Attributes
32+
harry.printDetails();
33+
john.printDetails();
34+
int salary = john.getSalary();
35+
System.out.println(salary);
36+
// System.out.println(harry.id);
37+
// System.out.println(harry.name);
38+
}
39+
}

0 commit comments

Comments
 (0)