[Solved] How do I set the variable to an incoming argument in java?


First, pass Address class as parameter.

void setAddress(Address s)

Since Address in a static nested class, but you have declared Address as String in your Problem3_1 class file. So you will need to concat the values manually like

void setAddress(Address s) {
        //address = s;

        address = s.number + " , " + s.street;
    }

This should work, if you’re creating and passing the values correctly.

Example:

    Problem3_1 a = new Problem3_1("name1",20,5);
    Problem3_1.Address a_address= new Problem3_1.Address(20,"1st street");
    a.setAddress(a_address);

    System.out.println(a.address);

This should print your desired output if you have override the toString() method in outer class as well as inner class.

UPDATE

http://ideone.com/rS20uZ – Check here for full code and output.

4

solved How do I set the variable to an incoming argument in java?