Guruh talabasi Qurbonov Tohirjonning Dasturlash1 fanidan taqdimoti


Interfeysni e'lon qilish va amalga oshirish


Download 98.42 Kb.
bet8/8
Sana18.06.2023
Hajmi98.42 Kb.
#1571789
1   2   3   4   5   6   7   8
Bog'liq
650-22guruh talabasi Qurbonov Tohirjonning Dasturlash1 fanidan taqdimoti

Interfeysni e'lon qilish va amalga oshirish

  • Interfeys kalit so'zi yordamida interfeys deklaratsiyasi:
  • public interface Animal {
  • String getSound(); // Interface methods are public by default}
  • Override Annotation
  • @Override
  • public String getSound() {
  • // Code goes here...}
  • This forces the compiler to check that we are overriding and prevents the program from defining a new method or
  • messing up the method signature.
  • Interfaces are implemented using the implements keyword.
  • public class Cat implements Animal {
  • @Override
  • public String getSound() {
  • return "meow"; }} 
  • public class Dog implements Animal {
  • @Override
  • public String getSound() {
  • return "woof"; }}

E’tiboringiz uchun rahmat


Download 98.42 Kb.

Do'stlaringiz bilan baham:
1   2   3   4   5   6   7   8




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling