Skip to content

. #21

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

. #21

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 24 additions & 0 deletions Human.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
public class Human {

public final static void staticPrint() {
System.out.println("This is a static method in Human class");
}

String fullName;

public String getFullName() {
return fullName;
}

public void setFullName(String fullName) {
this.fullName = fullName;
}

/* public void setFullName(String fullName) {
System.out.print(fullName);
}*/

public void sayMyName() {
System.out.println(" human " /* or fullName */ );
}
}
28 changes: 28 additions & 0 deletions Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
public class Main {
public static void main(String[]args) {

Human student = new Student();
Human professor = new Professor();
//بله بودند و خروجی true برای هردو چاپ شد

System.out.println(student instanceof Human);
System.out.println(professor instanceof Human);

Human human = new Student();
human.sayMyName();
// خروجی چاپ شده : null

Human human1 = new Professor();
human1.sayMyName();
// خروجی چاپ شده:null
//null

/*
دو سوال بالا نشان داد که تا وقتی که ورودی به متد sayName
داده نشود خروجی را بصورت پیش فرض null چاپ می کند و همچنین دو کلاس Student , Professor بصورت مجزا از کلاس Human
ارث بری می کنند
*/

}

}
33 changes: 33 additions & 0 deletions Professor.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
public class Professor extends Human {
private String professorFaculty;;
private int numberOfCourse;
private String professorSpecialty;

public String getProfessorFaculty(){
return professorFaculty;
}
public void setProfessorFaculty(String professorFaculty){
this.professorFaculty=professorFaculty;
}

public int getNumberOfCourse(){
return numberOfCourse;
}
public void setNumberOfCourse(int numberOfCourse){
this.numberOfCourse=numberOfCourse;
}

public String getProfessorSpecialty(){
return professorSpecialty;
}
public void setProfessorSpecialty(String professorSpecialty){
this.professorSpecialty=professorSpecialty;
}


public void sayMyName(){
System.out.println( getFullName());
System.out.println( getProfessorFaculty());
}

}
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
4. Main


- کلاس های professor و student از کلاس human ارث بری میکنند.
- کلاس های Professor و Student از کلاس Human ارث بری میکنند.


سوال 1: در کلاس Human متود ()staticPrint را طوری تغییر دهید که خروجی آن در کلاس هایی که کلاس Human را پیاده سازی می کنند قابل تغییر نباشد.
Expand All @@ -24,12 +24,12 @@
سوال 6: بعد از کامل کردن کلاس های Student و Professor یک نمونه از هرکدام بسازید و با استفاده از کلمه کلیدی instanceof چک کنید که آیا این دو نمونه واقعا نمونه ای از کلاس Human هستند یا نه.

سوال 7: کد مقابل را بنویسید.
#### Human human = new Student();
خروجی ()human.sayMyName چیست؟
#### Human Human = new Student();
خروجی ()Human.sayMyName چیست؟

سوال 8: حالا این کد را بنویسید.
#### Human human = new Professor();
خروجی ()human.sayMyName چیست؟
#### Human Human = new Professor();
خروجی ()Human.sayMyName چیست؟


سوال 9:
Expand Down
34 changes: 34 additions & 0 deletions Student.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
public class Student extends Human {
private int studentNumber;
private String majorName;
private String universityName;

@Override
public void sayMyName(){
System.out.println( getFullName());

}


public int getStudentNumber() {
return studentNumber;
}
public void setStudentNumber(int studentNumber) {
this.studentNumber = studentNumber;
}

public String getMajorName() {
return majorName;
}
public void setMajorName(String majorName) {
this.majorName = majorName;
}


public String getUniversityName() {
return universityName;
}
public void setUniversityName(String universityName) {
this.universityName = universityName;
}
}
24 changes: 24 additions & 0 deletions out/production/AP-1/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Compiled class file
*.class

# Log file
*.log

# BlueJ files
*.ctxt

# Mobile Tools for Java (J2ME)
.mtj.tmp/

# Package Files #
*.jar
*.war
*.nar
*.ear
*.zip
*.tar.gz
*.rar

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
replay_pid*
8 changes: 8 additions & 0 deletions out/production/AP-1/.idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions out/production/AP-1/.idea/AP-1.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions out/production/AP-1/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions out/production/AP-1/.idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

124 changes: 124 additions & 0 deletions out/production/AP-1/.idea/uiDesigner.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions out/production/AP-1/.idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 36 additions & 0 deletions out/production/AP-1/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
ترتیب کلاس ها برای کامل کردن:

1. Human
2. Student
3. Professor
4. Main


- کلاس های Professor و Student از کلاس Human ارث بری میکنند.


سوال 1: در کلاس Human متود ()staticPrint را طوری تغییر دهید که خروجی آن در کلاس هایی که کلاس Human را پیاده سازی می کنند قابل تغییر نباشد.

سوال 2: کلاس Student را طوری تغییر دهید که هنگام صدا زدن متود ()sayMyName بر روی آن، مشخصه fullName آن در خروجی چاپ شود.

سوال 3: مشخصه های زیر را با توابع Setter و Getter مناسب به کلاس Student اضافه کنید.
#### studentNumber, majorName, universityName

سوال 4: مشخصه های زیر را با توابع Setter و Getter مناسب به کلاس Professor اضافه کنید.
#### professorFaculty, numberOfCourse, professorSpecialty

سوال 5: کلاس Professor را طوری تغییر دهید که هنگام صدا زدن متود ()sayMyName بر روی آن، مشخصه fullName و professorFaculty در خروجی چاپ شود.

سوال 6: بعد از کامل کردن کلاس های Student و Professor یک نمونه از هرکدام بسازید و با استفاده از کلمه کلیدی instanceof چک کنید که آیا این دو نمونه واقعا نمونه ای از کلاس Human هستند یا نه.

سوال 7: کد مقابل را بنویسید.
#### Human Human = new Student();
خروجی ()Human.sayMyName چیست؟

سوال 8: حالا این کد را بنویسید.
#### Human Human = new Professor();
خروجی ()Human.sayMyName چیست؟


سوال 9:
از این دو مثال چه نتیجه ای می توان گرفت؟