#Difference between Shape circleObj = new Circle(); and Circle circleObj = new Circle();?
33 messages · Page 1 of 1 (latest)
⌛ This post has been reserved for your question.
Hey @tough marten! Please use
/closeor theClose Postbutton above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
Difference between Shape circleObj = new Circle(); and Circle circleObj = new Circle();?
You don't "need" those two statements. That there is more thzn one way to get the same result should not baffle you
We accept 1+1 and 1 + 1 out of convenience
The difference between your two lines is a compile-time difference, when you're writing the program. It doesn't change what the program does when you run it
The difference is the type of the variable. Probably a Circle class has methods that a Shape class does not have. So if your variable is of type Circle you can call getRadius() on it, and with a Shape variable you can't because not all shapes have a radius
That also means that if you make a variable of type Circle when that's not necessary, you won't be able to give it any other kind of shapes, so you're making your life difficult. Don't use specialized variable types when you don't need them specialized. Do use specizlized variable types when you do need them dpecialized
the difference is semantic. when you have a broader type, it says that the given variable could be a different type within that broader constraint
@pseudo pawn , I understand what you try to say.
It's also for the abstration and interfaces?
Abstraction isn't a keyword
It doesn't matter whether the supertype is a class or an interface. It works the same
In simple interface,
Movable car = new Car();
OR
In multiple interface,
Animal animal = new Animal();
Why, not doing the same as simple interface?
These examples don't seem related to the subject of multiple interfaces. Simple interface isn't a thing
what do you mean by "multiple interface" here even?
Have a look at their codes
Interface: https://g.co/bard/share/04a9773c7347
Multiple Interfaces: https://g.co/bard/share/47779a22000f
You cannot give names to stuff without showing them. That should be obvious with no need to mention
These two code samples try to demonstrate completely different things, so they do things differently
It's implemented by Animal subclass so?
It makes no sense trying to compare them
Ok
"It"?
I think so
Dude, what is "it"?
interface movable and eatable implements by Animal subclass.
Okay?
What I did wrong is I mixed two things
really?
It is. Abstraction is not
hehe.