

hi friend,
In your code you are only initializing the value and you are not getting the value try the modified code may this will be helpful for you.
UserName.java
package roseindia.net.example;
public class UserName {
protected String ivFirstName, ivLastName;
public UserName(String first, String last) {
ivFirstName = first;
ivLastName = last;
}
public String getUserName()
{
return ivFirstName+" "+ivLastName;
}
public String getFirstName() {
return ivFirstName;
}
public String getLastName() {
return ivLastName;
}
}
User.java
package roseindia.net.example;
public class User {
protected String ivFirstName = "Java";
protected String ivLastName = "Developer";
/**
* This is returning a single Object, which contains
* multiple values.
*/
public String getName() {
UserName un = new UserName(ivFirstName, ivLastName);
return un.getUserName();
}
}
Driver.java
package roseindia.net.example;
public class Driver {
public static void main (String[] args) {
User method = new User();
System.out.println(method.getName());
}
}

hi
modify your Driver.java class as
public class Driver {
public static void main (String[] args) {
User method = new User();
System.out.println(method.getName().getFirstName()+
" "+ method.getName().getLastName());
}
}
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.