package com.codegym.task.task02.task0208;
/*
One cat isn't enough
*/
public class Solution {
public static void main(String[] args) {
Car kitty = new Cat();
Cer limo = new Cat();//write your code here
}
public static class Cat {
}
}
Hi community :), why if i declare different names dont work? i dont see any requirements about that!
Under discussion
Comments (7)
- Popular
- New
- Old
You must be signed in to leave a comment
sonali singh
12 April 2019, 16:28useful
you have made kitty as a car type variable but you are you are using it as an object of Cat class i.e,Car kitty = new Cat(); and same for Cer limo = new Cat(); that's why its not working ....when you create any class you creates a new data type i.e, cat.....and when you are creating any object for that class you should you that class name as type ......so it will be now as:
Cat kitty = new Cat();
Cat limo = new Cat();
+2
sonali singh
12 April 2019, 16:30
please reply if you understood....
0
Sung Ju No
14 April 2019, 04:23
Thank you very much I think I was getting confused about the primitive type that we don’t need to create a class and the cat class!
0
carlos oliveira
11 April 2019, 07:17useful
Hello Sung :) . why if i declare different names dont work? you are working with objects("classes") . when you use the keyword "new" means you are creating a reference off an object that's mean you can just create a reference what you already have created , that's why you can't use any name. all right!! , but sure you can give any name to it when create it. i.e.
Cat Kitty = new Cat(); i think you got confused with the parameters : <obj> " anyname" = new <obj()>;
Cat limo = new Cat();
Cat cer = new Cat();
public static Cat{
}
+1
Sung Ju No
14 April 2019, 04:24
Thank you very much!
0
Philip Narteh
10 April 2019, 17:48
Your data types are "Car" and "Cer" instead of "Cat". Consider changing it and try again.
0
Sung Ju No
10 April 2019, 18:21
Thanks Philip but i dont see any requirement about that, shouldnt that work? even if i put differente data types?
0