-
Notifications
You must be signed in to change notification settings - Fork 15
/
inh.java
60 lines (52 loc) · 1.2 KB
/
inh.java
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
class Student{
private int id=102; //Instance variable
private String name;
// char c;
public void setId(int id)
{
this.id=id;
}
public int getId()
{
return this.id;
}
public void setname(String name)
{
this.name=name;
}
public String getname()
{
return this.name;
}
// public void show()
// {
// int id=101; //local variable
// System.out.println(this.id);
// System.out.println(id);
//}
}
public class inh {
public static void main(String args[])
{
Student obj=new Student(); // here new student is an object not obj new for asking class and student is constructor of class
// obj.id=101;
// obj.name="jatt";
//// obj.c;
//// System.out.println(obj.id);
// obj.show();
// System.out.println(obj.name);
// System.out.println(obj.c);
obj.setId(101);
obj.setname("johar");
int x=obj.getId();
String y=obj.getname();
System.out.println(x);
System.out.println(y);
}
}
// to acess private use getter and setter methods
//byte short int long =01
//
//float double=0.0
//
//char='\u0000'