Of course we can't then what it is :--
Drink beer = new AlcoholicBeer();
Can we make objects of interface???
Resolved
Comments (6)
- Popular
- New
- Old
You must be signed in to leave a comment
Misiu
28 July 2020, 15:44
It is an object - AlcoholicBeer.
This object is Drink type (has capabilities of Drink interface).
+2
Tata
1 August 2020, 12:43
Thanks Misiu for your time.
0
Sylwia
23 January 2021, 12:57
Misiu,
can you please explain when to do this? What are the advantages?
0
Misiu
24 January 2021, 02:52
Interfaces make sure that objects which implement them have common abilities.
In this task any drink which implements Drink interface must have ability to check if it is alcoholic or not (must have isAlcoholic() method).
Each drink object which implements Drink interface may be Drink type, so as such it can invoke isAlcoholic() method.
Of course, in this task we can create object beer which will be AlcoholicBeer type.
But this task shows usage of interfaces.
+2
Sylwia
24 January 2021, 14:17
Thank you Misiu :)
0
Hoist
15 November 2022, 05:36
Very helpful notes on programming abstract constructs
0