Person have name field of Name type..??

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();       
    }
}









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
Get Property by Name
Get computer name in java
If statement doesn't work ,(doesn't print alert message when user dont field name and email)
Java class name and file name are different
SQL Alter Column Name
Java Get File Name
Domain Name
Java Program MY NAME
NameError: name 'np' is not defined
My name, java project
My name, java project
"The folder name is not valid" netbeans
Stoting file name in Map
Change the name of the grades
parser error xmlparseentityref no name
docker remove image by name
NameError: name 'SparkConf' is not defined
Altering a Column name in a table
NameError: name 'SparkConf' is not defined
tag name in xml
Duplicate name in Manifest - Struts
No SDK with the name or path
personal name aliases
personal name aliases
NameError: name 'metrics' is not defined
Impact on change of table name
name of year in chinese
display the employee name
NameError: name 'false' is not defined
property name= hibernate.archive.autodetection
Set the mapping name
name of year in chinese
Name Displaying - JSP-Servlet
How to get the Day name
SQL Alter Column Name
Web Hosting Guide. Introduction to Domain Name
SQL Alter Table Name
Set the mapping name
Changing column name
Change Column Name in MySQL
Print initials of the input name
Use of name() function in XPath
How to extract name,surname, doamin name from mailid
Java file get name

Ads