|
new Student();
System.out
|
bet | 6/6 | Sana | 17.12.2023 | Hajmi | 21,46 Kb. | | #121647 |
Bog'liq Java Class Methods1new Student();
System.out.println("Name: " + myObj.fname);
System.out.println("Age: " + myObj.age);
System.out.println("Graduation Year: " + myObj.graduationYear);
myObj.study(); // call abstract method
}
}
Bu kod Main klassini abstrakt klass deb e'lon qiladi. Main klassida fname va age nomli xususiyatlar mavjud va study nomli abstract metod mavjud. Student klass esa Main klassidan meros olgan va study metodini uni o'z ichiga olgan subclass. Second klass esa Student klassini ishlatadi va uning obyektini yaratadi. Natijada, obyektning xususiyatlariga murojaat qilinadi va study metodini chaqiradi.
|
| |