"สวัสดี Amigo! อีกไม่นานคุณคงจะฝันถึงอินเทอร์เฟซ ดังนั้นฉันคงไม่หลับถ้าฉันเป็นคุณ ไม่มีทาง! ฮ่า ฮ่า! ต่อไปนี้คือแบบฝึกหัดเล็กๆ น้อยๆ สำหรับคุณ ขอให้อินเทอร์เฟซยังคงอยู่ในสมองของคุณ "
3
งาน
Java Core, ระดับ, บทเรียน
Wanna fly?
Rishi Gatesman, a CodeGym teacher, used to say that the interface is the legitimate child of Abstraction and Polymorphism. Let's start studying it. Have you ever flown in a dream? Have you ever dreamed of actually flying? Here's your task: implement the CanFly interface with two methods. Can you do it?
3
งาน
Java Core, ระดับ, บทเรียน
Fly, run and swim
It would be awesome to be Superman! He flies fast as lightning, outruns the wind, and swims like a fish. Wait, can Superman even swim? Whatever, doesn't matter. Write a generic template for a superhero that can fly, swim, and run. You need to do this by implementing the CanFly, CanRun, and CanSwim interfaces.
3
งาน
Java Core, ระดับ, บทเรียน
Eat, fly, and move
Some kind soul already wrote for you perfect interfaces for flying, moving, and eating. Let's add these interfaces to the dog, duck, car, and airplane classes. Let common sense be your guide as you dream up the solution. Sometimes common sense is a programmer's best friend.
3
งาน
Java Core, ระดับ, บทเรียน
Making a human
No fancy bells and whistles in this task. We simply need to correctly associate the CanFly, CanRun, and CanSwim interfaces with the Human, Duck, Penguin, and Airplane classes. Can you do it? Carry on! Don't know how? Go study the corresponding lesson, and then - carry on!
3
งาน
Java Core, ระดับ, บทเรียน
Human class and CanRun and CanSwim interfaces
Once again, like real programmers, we have to create a human. And, as always, we will accomplish this by writing code. Alas. We'll grant our human the Run and Swim interfaces, but we won't implement them. Because our man is abstract. Make sense? If not, it's time to review the lessons on abstract classes and interfaces.