-
Notifications
You must be signed in to change notification settings - Fork 0
/
BasicHuman.java
73 lines (70 loc) · 1.46 KB
/
BasicHuman.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import java.io.*;
import java.util.*;
class Human
{
public void display ()
{
System.out.println ("I am Human, I am the parent class");
}
}
//inheritance
class Woman extends Human
{
@Override public void display ()
{
System.out.println ("I am a Woman, I am the child class of Human");
}
public String womanDetails (String name)
{
return name;
}
//Overload
public int womanDetails (int age)
{
return age;
}
}
//encapsulation
class Relation
{
//private keyword performs data hiding
private String related;
//setters and getter to bind date members and member functions
public String getName ()
{
return related;
}
public void setName (String relate)
{
related = relate;
}
}
//abstraction
abstract class Profession
{
public abstract void present ();
}
class Engineer extends Profession
{
public void present ()
{
System.out.println ("\nWe are Engineers!");
}
}
class BasicHuman
{
public static void main (String[]args)
{
Human human = new Human ();
human.display ();
Woman woman = new Woman ();
woman.display ();
System.out.println (woman.womanDetails ("Keerthana"));
System.out.println (woman.womanDetails (20));
Relation encap = new Relation ();
encap.setName ("BestFriends");
System.out.print ("We are : " + encap.getName ());
Engineer prof = new Engineer ();
prof.present ();
}
}