Java Tutorial 4.1 Packages Part 1/12 - interfaces
Uploader Comments (Zantorc)
Video Responses
All Comments (6)
-
You're welcome.
-
Yes that's right.
-
Or to use another example an Interface is a like a remote control that controls a TV,Stereo etc.You dont have to know how the TV,Stereo works but just know how the remote works. This is so clear now. Thank you for your help friend!
-
Yes, it dawned on me yesterday. An interface is like a "wrapper" that you would wrap different objects in, looking the same to the class that uses the interface whilst hiding the complexities of the objects inside.But the objects themselves would behave differently right?
-
Remember you can only inherit from 1 class - that would be a serious limitation if that was all there was. I go into a lot more detail in part 17 but maybe I should add some more motivation for using interfaces in this part.
-
If you only ever implemented the interface in one class, you'd be right, interfaces wouldn't be of much use. If 2 or more classes implement an interface then its a different story. An interface is a type just like a class is, you can declare fields and parameters of that interface type and it will accept anything that implements it. Suddenly you are able to treat different classes as the same if they share an interface (its called polymorphism).
-
Why have an Interface with methods in it that doesnt do anything when you can write a class with the full implementation of said methods in the first place???
-
OK I've just modified the video. All methods in interfaces are implicitly 'public' (and 'abstract' which I'm about to cover in the next video). You don't have to put public (or abstract) in. (You can if you want, but since public is the only access modifier allowed in interfaces the language designers saw little point in forcing you to add it). As I said this is only a superficial look at interfaces, the detailed stuff will be posted soon.
Ok.Tell me about Anonymous Inner Classes then - its implementation and why its used! Thank you for your time..
vja1970 3 years ago
Have looked at playlist number 23 which covers anonymous classes (about 45 mins long). It may help also to cover 20 21 and 22 first (around 3 hours in all).
If you check my play lists you'll find it much easier.
Zantorc 3 years ago