Forwarded from تجمع شيتات واسئلة oop
YouTube
#044 [JAVA] - Types of Relationships (Association, Aggregation "has-a", Composition "part-of")
كورس البرمجة الكينونية باستخدام لغة البرمجة جافا:
شرح أنواع العلاقات (علاقة الجزء بالكل)، علاقة التجميع، علاقة المركب
~
Explain Types of Relationships
Association "has-a" relationship
Aggregation "has-a" relationship
Composition "part-of" relationship
Whole…
شرح أنواع العلاقات (علاقة الجزء بالكل)، علاقة التجميع، علاقة المركب
~
Explain Types of Relationships
Association "has-a" relationship
Aggregation "has-a" relationship
Composition "part-of" relationship
Whole…
Forwarded from تجمع شيتات واسئلة oop
❤3
class Person {
String name;
int age;
Person(String name, int age) {
this.name = name;
this.age = age;
}
String introduce() {
return "My name is " + name + " and I am " + age + " years old.";
}
}
class Student extends Person {
String studentId;
Student(String name, int age, String studentId) {
super(name, age);
this.studentId = studentId;
}
@Override
String introduce() {
return super.introduce() + " My student ID is " + studentId + ".";
}
}
class Teacher extends Person {
String subject;
Teacher(String name, int age, String subject) {
super(name, age);
this.subject = subject;
}
@Override
String introduce() {
return super.introduce() + " I teach " + subject + ".";
}
}
public class Main {
public static void main(String[] args) {
Student student = new Student("Mariam", 20, "S12345");
Teacher teacher = new Teacher("Ahmed", 40, "Mathematics");
System.out.println(student.introduce());
System.out.println(teacher.introduce());
}
}
output?