My Code ::
public class Solution {
public static void main(String[] args) {
Dog Max = new Dog();
Dog Bella = new Dog();
Dog Jack = new Dog();
//write your code here
}
public static class Dog {
public String name;
}
}
Question is ::
Why condition ''Each Dog object must be assigned a name'' is not getting fulfilled here ? I think i m missing something.
Why condition ''Each Dog object must be assigned a name'' is not getting fulfilled here ?
Under discussion
Comments (9)
- Popular
- New
- Old
You must be signed in to leave a comment
Pooja Kengale
16 October 2019, 10:44
try this
package com.codegym.task.task02.task0209;
/*
Max, Bella, and Jack
*/
public class Solution {
public static void main(String[] args) {
Dog dog1 = new Dog();
dog1.name = "Max";
//write your code here
Dog d2 = new Dog();
d2.name = "Bella";
Dog d3 = new Dog();
d3.name = "Jack";
}
public static class Dog {
public String name;
}
}
0
salma md
16 May 2019, 16:38
package com.codegym.task.task02.task0209;
/*
Max, Bella, and Jack
*/
public class Solution {
public static void main(String[] args) {
Dog dog1 = new Dog();
Dog Bella = new Dog();
Dog Jack = new Dog();
dog1.name = "Max";
Bella.name="Bella";
Jack.name="Jack";
//write your code here
// Dog max = new Dog();
}
public static class Dog {
public String name;
}
}
0
Thomas
16 May 2019, 04:47
Thanks Rishi Raj
0
sitedevelop
2 May 2019, 14:19
It means you can't assign a string value to object itself, you can only assign string value to object's string property
0
sneha
25 February 2019, 11:25
you still need to assign a value to the name variable such that
Max.name="Max";
Bella.name="Bella";
Jack.name="Jack";
0
Rishi Raj
1 December 2018, 20:14
public class Solution {
public static void main(String[] args) {
Dog dog1 = new Dog();
Dog dog2 = new Dog();
Dog dog3 = new Dog();
dog1.name = "Max";
dog2.name = "Bella";
dog3.name = "Jack";
//write your code here
}
public static class Dog {
public String name;
}
}
+1
Martin
17 January 2019, 08:59
Same "problem" for me. I understand to your method, but why our method is wrong? Resut is the same, it is not?
Dog Max = new Dog();
Dog Bella = new Dog();
Dog Jack = new Dog();
0
Guadalupe Gagnon
17 January 2019, 14:40
Martin:
You still need to assign a value to the name variable such that:
This is the step that is missing from yours and the original poster. You will need to do this for all three of the dogs that you created. 0
Michael Martin
16 November 2018, 17:51
You have to assign a value (name) to each dog variable via the name class member. Example: Max.name = "Max";
+1