File tree 1 file changed +39
-0
lines changed
1 file changed +39
-0
lines changed Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments