تجمع شيتات واسئلة oop
813 subscribers
345 photos
12 videos
166 files
37 links
شوفو التثبيتات واتركو لنا دعوة جزاكم الله خيرا. 🤍
Download Telegram
Forwarded from Khirallah Elferjani
find output OOP.pdf
430.2 KB
شرح ايمان الساحلي ⬇️⬇️
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?
interface Identifiable {
String getId();
}

abstract class Person {
private String name;
private int age;

public Person(String name, int age) {
this.name = name;
this.age = age;
}

public String introduce() {
return "My name is " + name + " and I am " + age + " years old.";
}

public abstract String getRole();
}

class Student extends Person implements Identifiable {
private String studentId;

public Student(String name, int age, String studentId) {
super(name, age);
this.studentId = studentId;
}

@Override
public String getId() {
return studentId;
}

@Override
public String getRole() {
return "Student";
}

@Override
public String introduce() {
return super.introduce() + " I am a " + getRole() + ". My student ID is " + getId() + ".";
}
}

class Teacher extends Person implements Identifiable {
private String subject;
private String teacherId;

public Teacher(String name, int age, String subject, String teacherId) {
super(name, age);
this.subject = subject;
this.teacherId = teacherId;
}

@Override
public String getId() {
return teacherId;
}

@Override
public String getRole() {
return "Teacher";
}

@Override
public String introduce() {
return super.introduce() + " I am a " + getRole() + ". I teach " + subject + ". My ID is " + getId() + ".";
}
}

public class Main {
public static void main(String[] args) {
Person student = new Student("Mariam", 20, "S12345");
Person teacher = new Teacher("Ahmed", 40, "Mathematics", "T98765");

System.out.println(student.introduce());
System.out.println(teacher.introduce());
}
}

output!
👍1
interface Role {
String getRole();
}

abstract class Person {
String name;
Person(String name) { this.name = name; }
abstract String details();
}

class Student extends Person implements Role {
String id;
Student(String name, String id) { super(name); this.id = id; }
public String getRole() { return "Student"; }
String details() { return name + " is a " + getRole() + " with ID: " + id; }
}

public class Main {
public static void main(String[] args) {
Person student = new Student("Mariam", "S12345");
System.out.println(student.details());
}
}
طبعا زرو على كود هيطلع كامل...
هكي افضل مظهر لشاشة 🍃
3