EASY_JAVA_RU Telegram 1990
🤔 К какому принципу ООП относится переопределение методов?

Переопределение методов (Method Overriding) относится к полиморфизму – одному из ключевых принципов ООП.

🚩Как работает переопределение (`@Override`)?

Переопределение (Overriding) – это когда подкласс изменяет поведение метода родительского класса.
class Animal {
void makeSound() {
System.out.println("Какое-то животное издаёт звук");
}
}

class Dog extends Animal {
@Override
void makeSound() {
System.out.println("Гав-гав!");
}
}

class Cat extends Animal {
@Override
void makeSound() {
System.out.println("Мяу!");
}
}


Используем полиморфизм
public class Main {
public static void main(String[] args) {
Animal myAnimal = new Dog(); // Полиморфизм
myAnimal.makeSound(); // Выведет "Гав-гав!"
}
}



🚩Переопределение = полиморфизм времени выполнения (Runtime Polymorphism)

Перегрузка (Overloading) – полиморфизм времени компиляции (Compile-time).
Переопределение (Overriding) – полиморфизм времени выполнения (Runtime).

🚩Когда нужно переопределять методы?

Когда подкласс должен изменить поведение родительского класса.
Когда работаем с абстрактными классами и интерфейсами.
Когда используем полиморфизм для гибкости кода.

Ставь 👍 и забирай 📚 Базу знаний
Please open Telegram to view this post
VIEW IN TELEGRAM
👍8



tgoop.com/easy_java_ru/1990
Create:
Last Update:

🤔 К какому принципу ООП относится переопределение методов?

Переопределение методов (Method Overriding) относится к полиморфизму – одному из ключевых принципов ООП.

🚩Как работает переопределение (`@Override`)?

Переопределение (Overriding) – это когда подкласс изменяет поведение метода родительского класса.

class Animal {
void makeSound() {
System.out.println("Какое-то животное издаёт звук");
}
}

class Dog extends Animal {
@Override
void makeSound() {
System.out.println("Гав-гав!");
}
}

class Cat extends Animal {
@Override
void makeSound() {
System.out.println("Мяу!");
}
}


Используем полиморфизм
public class Main {
public static void main(String[] args) {
Animal myAnimal = new Dog(); // Полиморфизм
myAnimal.makeSound(); // Выведет "Гав-гав!"
}
}



🚩Переопределение = полиморфизм времени выполнения (Runtime Polymorphism)

Перегрузка (Overloading) – полиморфизм времени компиляции (Compile-time).
Переопределение (Overriding) – полиморфизм времени выполнения (Runtime).

🚩Когда нужно переопределять методы?

Когда подкласс должен изменить поведение родительского класса.
Когда работаем с абстрактными классами и интерфейсами.
Когда используем полиморфизм для гибкости кода.

Ставь 👍 и забирай 📚 Базу знаний

BY Java | Вопросы собесов


Share with your friend now:
tgoop.com/easy_java_ru/1990

View MORE
Open in Telegram


Telegram News

Date: |

Although some crypto traders have moved toward screaming as a coping mechanism, several mental health experts call this therapy a pseudoscience. The crypto community finds its way to engage in one or the other way and share its feelings with other fellow members. To edit your name or bio, click the Menu icon and select “Manage Channel.” Today, we will address Telegram channels and how to use them for maximum benefit. While the character limit is 255, try to fit into 200 characters. This way, users will be able to take in your text fast and efficiently. Reveal the essence of your channel and provide contact information. For example, you can add a bot name, link to your pricing plans, etc. The court said the defendant had also incited people to commit public nuisance, with messages calling on them to take part in rallies and demonstrations including at Hong Kong International Airport, to block roads and to paralyse the public transportation system. Various forms of protest promoted on the messaging platform included general strikes, lunchtime protests and silent sit-ins.
from us


Telegram Java | Вопросы собесов
FROM American