Person have name field of Name type..??

Ads
 

Person have name field of Name type..??

Person have name field of Name type means i understood to create new Name class with fields firstname, middlename, and lastname but i dont know how to use this class in person to give him name?

can you please write code two two different class and show me how to use?

View Answers

June 4, 2013 at 11:32 AM

hi friend,

Try the following code may this will be helpful for you

package net.roseindia.simpleExample;

public class Name {

    String firstName;
    String middleName;
    String lastName;

    public Name()
    {       
    }   
    public Name(String firstName, String middleName, String lastName)
    {
        this.firstName = firstName;
        this.middleName = middleName;
        this.lastName = lastName;
    }
    public String getFirstName() {
        return firstName;
    }
    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }
    public String getMiddleName() {
        return middleName;
    }
    public void setMiddleName(String middleName) {
        this.middleName = middleName;
    }
    public String getLastName() {
        return lastName;
    }
    public void setLastName(String lastName) {
        this.lastName = lastName;
    }

    public String displayName()
    {       
        return getFirstName()+" "+ getMiddleName()+" "+getLastName();
    }
}

Continue....


June 4, 2013 at 11:37 AM

package net.roseindia.simpleExample;

public class Person {

    Name name;

    public Person()
    {       
    }   
    public Person(Name name) {
        super();
        this.name = name;
    }   
    public void display()
    {
        System.out.println(name.displayName());     
    }
}

Continue...


June 4, 2013 at 11:37 AM

package net.roseindia.simpleExample;

public class Main {

    public static void main(String args[])
    {
        Name name = new Name();
        name.setFirstName("Bipul");
        name.setMiddleName("Kumar");
        name.setLastName("Choudhary");

        //Name name = new Name("Bipul", "Kumar", "Choudhary");

        Person person = new Person(name);
        person.display();       
    }
}

Ads









Related Tutorials/Questions & Answers:
Person have name field of Name type..??
Name
Advertisements
depending on the form name i have to display the message
Name unique
search for a name
class name
If statement doesn't work ,(doesn't print alert message when user dont field name and email)
Get computer name in java
SQL Alter Column Name
Java Program MY NAME
Java Get File Name
Stoting file name in Map
NameError: name 'np' is not defined
My name, java project
My name, java project
SQL Alter Column Name
NameError: name 'SparkConf' is not defined
NameError: name 'SparkConf' is not defined
tag name in xml
docker remove image by name
parser error xmlparseentityref no name
personal name aliases
personal name aliases
NameError: name 'metrics' is not defined
Impact on change of table name
name of year in chinese
No SDK with the name or path
Change Column Name in MySQL
display the employee name
NameError: name 'false' is not defined
property name= hibernate.archive.autodetection

Ads