Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Create a Adult Class !
- public class Adult {
- private String name,prof;
- private double height ;
- public Adult () {
- System.out.println("Enter name height prof :");
- }
- // Create constructor For Three Details!
- public Adult(String name,double height , String prof) {
- this.name=name;
- this.height=height;
- this.prof=prof;
- }
- public Adult(String name, double height) {
- this(name,height,"");
- }
- // Create Copy constructor !
- public Adult(Adult other ) {
- name=other.name;
- height=other.height;
- prof=other.prof;
- }
- //Create Set And Get FoR DeTails !
- public String getName() {
- return name;
- }
- public void setName(String name) {
- this.name = name;
- }
- public String getProf() {
- return prof;
- }
- public void setProf(String prof) {
- this.prof = prof;
- }
- public double getHeight() {
- return height;
- }
- public void setHeight(double height) {
- this.height = height;
- }
- //Create An Function That Print All The Details i want !
- public void printDetails() {
- if (prof.length() > 0 ) {
- System.out.print("name:"+ name + ":height:" + height+ ":prof:"+prof );
- }
- else {
- System.out.println("name:"+name+":height:"+height);
- }
- }
- }
- ##############################################################################################################################
- public class Tester {
- public static void main(String[] args) {
- // Here I Can Send The Details To The PRINTDETAILS Function That Print All The Details i Sent !
- Adult p1 = new Adult("Jan",1.80,"OfficeDepot");
- Adult p2 = new Adult("Waleed",1.57);
- Adult p3 = new Adult ("Hani",1.76,"Hackeru");
- p1.printDetails();
- System.out.println();
- p2.printDetails();
- System.out.println();
- p3.printDetails();
- System.out.println();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement