Afrikaans
Akan
Albanian
Amharic
Arabic
Armenian
Azerbaijani
Basque
Belarusian
Bemba
Bengali
Bihari
Bosnian
Breton
Bulgarian
Cambodian
Catalan
Cebuano
Cherokee
Chichewa
Chinese (Simplified)
Chinese (Traditional)
Corsican
Croatian
Czech
Danish
Dutch
English
Esperanto
Estonian
Ewe
Faroese
Filipino
Finnish
French
Frisian
Ga
Galician
Georgian
German
Greek
Guarani
Gujarati
Haitian Creole
Hausa
Hawaiian
Hebrew
Hindi
Hmong
Icelandic
Igbo
Indonesian
Interlingua
Irish
Italian
Japanese
Javanese
Kannada
Kazakh
Kinyarwanda
Kirundi
Kongo
Korean
Krio (Sierra Leone)
Kurdish
Kurdish (Soranรฎ)
Kyrgyz
Laothian
Latin
Latvian
Lingala
Lithuanian
Lozi
Luganda
Luo
Luxembourgish
Macedonian
Malagasy
Malay
Malayalam
Maltese
Maori
Marathi
Mauritian Creole
Moldavian
Mongolian
Myanmar (Burmese)
Montenegrin
Nepali
Nigerian Pidgin
Northern Sotho
Norwegian
Norwegian (Nynorsk)
Occitan
Oriya
Oromo
Pashto
Persian
Polish
Portuguese (Brazil)
Portuguese (Portugal)
Punjabi
Quechua
Romanian
Romansh
Runyakitara
Russian
Samoan
Scots Gaelic
Serbian
Serbo-Croatian
Sesotho
Setswana
Seychellois Creole
Shona
Sindhi
Sinhalese
Slovak
Slovenian
Somali
Spanish
Spanish (Latin American)
Sundanese
Swahili
Swedish
Tajik
Tamil
Tatar
Telugu
Thai
Tigrinya
Tonga
Tshiluba
Tumbuka
Turkish
Turkmen
Twi
Uighur
Ukrainian
Urdu
Uzbek
Vietnamese
Welsh
Wolof
Xhosa
Yiddish
Yoruba
Zulu
An interface defines method that a class needs to implement.
If a class implements an interface, it must override all of the methods inside the interface.
In this lesson, one of your classes is going to implement an interface.
An interface is a contract, and the contract defines methods that a class needs to implement.
Use an interface to define behavior that's required from a class, because if a class implements an
interface, it must override all of the methods inside the interface.
You can define an interface the way you would define a class public interface, followed by the interface
name.
And inside the interface, you can define method signatures, a class that implements this interface
must override every method inside of its.
So looking back at the requirements, we see that pense are eligible for 50 percent discounts, but
shirts are not.
But what I want to do is force the pants class to implement this behavior.
So I'll define an interface, create a new file, discounted Java.
And inside this kind of job, Java make this an interface.
And we're going to force every class and implement this interface to override a public void method called
discount.
And now inside Penstock Java, we can say that the pants class implements the discount interface.
When a class implements an interface, it's basically signing a contract that it's going to override
all of the methods inside the interface.
And here we have to honor the contract to override discount.
And we're going to offer a 50 percent discount by saying superdog set price.
Superdog get price divided by two.
And now the air is gone.
So back in Maine, we can call Penn student discount.
Put a breakpoint, launched the debugger.
And the price of the object went down by 50 percent.
Now, what's really interesting is that interfaces allow for polymorphism.
Because pants are discounted so we can declare the object as type discounted.
Keep this in mind for your next quiz.
An interface is a contract.
It defines methods that a class needs to implement.
When a class implements an interface, it signs the contract, therefore the class must override all
of the methods inside the interface.
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.