Click here to watch in Youtube :
https://www.youtube.com/watch?v=p_4U_LVMbSk&list=UUhwKlOVR041tngjerWxVccw
Click the below Image to Enlarge
Java Tutorial : Inheritance Has A Relationship (Person) |
Java Tutorial : Inheritance Has A Relationship (Person) |
Java Tutorial : Inheritance Has A Relationship (Person) |
Java Tutorial : Inheritance Has A Relationship (Person) |
Java Tutorial : Inheritance Has A Relationship (Person) |
public class Person
{ private String name; private int age; public Person(String name, int age) { super(); this.name = name; this.age = age; } public String getName() { return name; } public void setName(String name) { this.name = name; } public int getAge() { return age; } public void setAge(int age) { this.age = age; } @Override public String toString() { return "Person [name=" + name + ", age=" + age + "]"; } }
public class Address { private String street; private String city; private String state; private String zip; public Address(String street, String city, String state, String zip) { super(); this.street = street; this.city = city; this.state = state; this.zip = zip; } public String getStreet() { return street; } public void setStreet(String street) { this.street = street; } public String getCity() { return city; } public void setCity(String city) { this.city = city; } public String getState() { return state; } public void setState(String state) { this.state = state; } public String getZip() { return zip; } public void setZip(String zip) { this.zip = zip; } @Override public String toString() { return "Address [street=" + street + ", city=" + city + ", state=" + state + ", zip=" + zip + "]"; } }
/** * * Employee class extends Person class means Employee IS-A Person. * * Employee extends Person and thus inherits all methods and properties from * Person (except final and static). * * Employee can also define all its specific functionality. */ public class Employee extends Person { private String departmentName; private int employeeId; /* * Employee HAS-A Address */ private Address address; public Employee(String name, int age, String departmentName, int employeeId, Address address) { super(name, age); this.departmentName = departmentName; this.employeeId = employeeId; this.address = address; } public String getDepartmentName() { return departmentName; } public void setDepartmentName(String departmentName) { this.departmentName = departmentName; } public int getEmployeeId() { return employeeId; } public void setEmployeeId(int employeeId) { this.employeeId = employeeId; } public Address getAddress() { return address; } public void setAddress(Address address) { this.address = address; } @Override public String toString() { return "Employee [departmentName=" + departmentName + ", employeeId=" + employeeId + ", address=" + address + ", getName()=" + getName() + ", getAge()=" + getAge() + "]"; } }
/** * * Student class extends Person class means Student IS-A Person. * * Student extends Person and thus inherits all methods and properties from * Person (except final and static). * * Student can also define all its specific functionality. */ public class Student extends Person { private double grade; private int rollNo; /* * Student HAS-A Address */ private Address address; public Student(String name, int age, double grade, int rollNo, Address address) { super(name, age); this.grade = grade; this.rollNo = rollNo; this.address = address; } public double getGrade() { return grade; } public void setGrade(double grade) { this.grade = grade; } public int getRollNo() { return rollNo; } public void setRollNo(int rollNo) { this.rollNo = rollNo; } public Address getAddress() { return address; } public void setAddress(Address address) { this.address = address; } @Override public String toString() { return "Student [grade=" + grade + ", rollNo=" + rollNo + ", address=" + address + ", getName()=" + getName() + ", getAge()=" + getAge() + "]"; } }
public class RelationshipDemo { public static void main(String[] args) { Address peterAddress = new Address("13th Cross", "Bangalore", "Karnataka", "560001"); Employee peter = new Employee("Peter", 33, "Income Tax Department", 350, peterAddress); System.out.println("Employee Peter Details : "); System.out.println(peter); System.out.println("----------------------------------------------"); Address johnAddress = new Address("17th Cross", "Chennai", "TamilNadu", "600100"); Student john = new Student("John", 33, 3.5, 2, johnAddress); System.out.println("Student john Details : "); System.out.println(john); } }Output
Employee Peter Details : Employee [departmentName=Income Tax Department, employeeId=350, address=Address [street=13th Cross, city=Bangalore, state=Karnataka, zip=560001], getName()=Peter, getAge()=33] ---------------------------------------------- Student john Details : Student [grade=3.5, rollNo=2, address=Address [street=17th Cross, city=Chennai, state=TamilNadu, zip=600100], getName()=John, getAge()=33]To Download InheritanceDemo-HAS-A-PersonApp Project Click the below link
https://sites.google.com/site/javaee4321/java/InheritanceDemo-HAS-A-PersonApp.zip?attredirects=0&d=1
See also:
online training on java
ReplyDeleteExcellent Blog
ReplyDeleteThanks for this wonderful blog it is very useful content for us. Visit my website to get best Information About Data Science Training in Noida and mention Below Technologies.
Python Training in Noida
Data Science Training in Noida
java Training in Noida
full stack Development Training in Noida
Software Testing Training in Noida
Summer Training in noida
Web Development Training in Noida
Django Training in Noida
Ethical Hacking Training in Noida
Digital Marketing Training in Noida
Excellent Blog
ReplyDeleteThanks for this wonderful blog it is very useful content for us. Visit my website to get best Information About Data Science Training in Noida and mention Below Technologies.
Python Training in Noida
Data Science Training in Noida
java Training in Noida
full stack Development Training in Noida
Software Testing Training in Noida
Summer Training in noida
Web Development Training in Noida
Django Training in Noida
Ethical Hacking Training in Noida
Digital Marketing Training in Noida
Excellent Blog
ReplyDeleteThanks for this wonderful blog it is very useful content for us. Visit my website to get best Information About Data Science Training in Noida and mention Below Technologies.
Python Training in Noida
Data Science Training in Noida
java Training in Noida
full stack Development Training in Noida
Software Testing Training in Noida
Summer Training in noida
Web Development Training in Noida
Django Training in Noida
Ethical Hacking Training in Noida
Digital Marketing Training in Noida
Thanks for Sharing
ReplyDeleteBest Online Summer Internship Training
Summer Training in Noida
Python Training in Noida
Machine Learning Training in Noida
Data Science Training in Noida
Digital Marketing Training in Noida
Best Online Training Company
Best Online Internship Training Company
Best Online Summer Internship Training
ReplyDeleteSummer Training in Noida
Python Training in Noida
Machine Learning Training in Noida
Data Science Training in Noida
Digital Marketing Training in Noida
Best Online Training Company
Best Online Internship Training Company
Best Online Summer Internship Training
ReplyDeleteSummer Training in Noida
Python Training in Noida
Machine Learning Training in Noida
Data Science Training in Noida
Digital Marketing Training in Noida
Python Training in Noida
ReplyDeleteMachine Learning Training in Noida
Data Science Training in Noida
Digital Marketing Training in Noida
Best Online Training Company
Best Online Internship Training Company
I appreciate you sharing this wonderful content. It's exactly what I was hoping to see, and I sincerely hope you'll keep publishing great posts like this in the future.
ReplyDeleteSports Injury Rehabilitation in Surrey
I appreciate you sharing this wonderful content. It's exactly what I was hoping to see, and I sincerely hope you'll keep publishing great posts like this in the future.
ReplyDeleteSports Injury Rehabilitation in Surrey
Great blog post! Your insights are truly valuable and well-expressed. I appreciate the depth of information and the engaging writing style. Looking forward to more enlightening content from your blog in the future. If you are looking for professional Job oriented course like
ReplyDeletePython Training in noida
Data Science Training in noida
full stack development training in noida
Software Testing Training in Noida
Digital Marketing Training in Noida
SQL Training In Hyderabad
ReplyDeletebest SQL training institute in hyderabad
SQL training in ameerpet
SQL server Training in Hyderabad
sql Training
sql Online Training
sql server Online Training in Hyderabad
sql Online Training institute
sql server Training institute in Ameerpet
sql server Course in Hyderabad
Great Post! I found your insights really interesting. Looking forward to more from you.If you are looking for job oriented courses then visit Appwars Technologies provides these courses:-
ReplyDeleteBest Django training
Great Post! I found your insights really interesting. Looking forward to more from you.If you are looking for job oriented courses then visit Appwars Technologies provides these courses:-
ReplyDeleteBest Django training
Journal of P2P Network
ReplyDeletejournal of p2p network trends
peer-to-peer network engineering
p2p network Journal
journal of peer to peer network
international journal of p2p network trends
p2p network technology journal
peer 2 peer technology journal
Needed to compose you a very little word to thank you yet again regarding the nice suggestions you’ve contributed here.
ReplyDeletehttps://coursejet.com/digital-marketing-courses-in-chennai/
Fantastic post! Your writing style is informative yet brief, and I value the useful ideas you have shared. Anticipating more interesting posts from you. Keep going!
ReplyDeletewall decoration items for pooja
Fantastic post! Your writing style is informative yet brief, and I value the useful ideas you have shared. Anticipating more interesting posts from you. Keep going!
ReplyDeletewall decoration items for pooja
Very Nice Blog . Thanks for Posting
ReplyDeleteRead my Blog Python Training in Noida
Machine Learning Training in Noida
Data Science Training in Noida
Digital Marketing Training in Noida
Best Online Training Company
Best Online Internship Training Company
mathematics journals
ReplyDeletebest scopus indexed journals for mathematics science
mathematics science journals in india
mathematics science journals ranking
scopus indexed mathematics science journals
mathematics science journals scopus indexed
international journal for mathematics science
mathematics science peer reviewed journals
mathematics science scopus indexed journals
journals for mathematics science
This is one awesome article. Thanks Again. Really Great.
ReplyDeleteSAP S4 Hana Basis Training Institute
Oracle SOA Training From US|UK|AUS|Switzerland
SCOM 2019
ssrg
ReplyDeleteinternational journal of scientific engineering research
elsevier engineering journals
international journal of engineering and scientific research
engineering journals with high impact factor
engineering journal ranking
international journal for engineering
international electrical engineering journal
engineering elsevier journal
scopus indexed engineering journals
engineering journal publication
Such a interesting content and information about it . Thanks for Posting
ReplyDeleteData Analytics Training in Noida
Such a interesting content and information about it . Thanks for Posting
ReplyDeleteData Science Training in Noida
What a fascinating blog post! Concise but thorough, the information offers insightful information. I like how easily understood and interesting the author's writing is. Anticipating more
ReplyDeletebuy antique table decor
What a fascinating blog post! Concise but thorough, the information offers insightful information. I like how easily understood and interesting the author's writing is. Anticipating more
ReplyDeletebuy antique table decor
Best Online Summer Internship Training
ReplyDeleteSummer Training in Noida
Python Training in Noida
Machine Learning Training in Noida
Data Science Training in Noida
Digital Marketing Training in Noida
Best Online Summer Internship Training
ReplyDeleteSummer Training in Noida
Python Training in Noida
Machine Learning Training in Noida
Data Science Training in Noida
Digital Marketing Training in Noida
Very Nice Blog . Thanks for Posting
ReplyDeleteI found this post really interesting. This information is beneficial for those who are looking for
Python Training in Noida
Machine Learning Training in Noida
Data Science Training in Noida
Digital Marketing Training in Noida
Data Analytics Training in Noida
Best Online Training Company
Best Online Internship Training Company
Very Nice Blog . Thanks for Posting
ReplyDeleteI found this post really interesting. This information is beneficial for those who are looking for
Python Training in Noida
Machine Learning Training in Noida
Data Science Training in Noida
Digital Marketing Training in Noida
Data Analytics Training in Noida
Best Online Training Company
Best Online Internship Training Company