OOP: nähtavus (private, protected, public, tühi)¶
Nähtavuse modifikaatorid võimaldavad määrata klassi ning selle klassi väljade nähtavust¶
Ülevaateliselt näitab allolev tabel erinevate modifikaatorite mõju kaugust.
-
Package = pakett
-
Subclass = alamklass
-
same pkg, diff pkg = sama pakett, teine pakett
private¶
Meetoditele, muutujatele ning konstruktoritele, mis on määratud kui private, saab ligi ainult samast klassist. Private ligipääs on kõige piiravam ligipääs ning klassid ja liidesed (interface) ei saa olla privaatsed. Muutujatele, mis on deklareeritud kui private, saab ligi teistest klassidest, kui nendes on olemas getter’id ja setter’id. Kasutades private nähtavust on võimalik olla kindel, et objekt peidab oma infot välismaailma eest.
public class Student {
private String name;
public String getName() {
return this.name;
}
public void setName(String name) {
this.name = name;
}
}
Kuna me ei saa teistest klassidest Student klassi muutuja(te)le ligi, siis kasutame kahte public meetodit, getName() ja setName(String name), et tagastada name väärtus või soovi korral seada see väärtus.
private void privateMethod() {
System.out.println("Tere! Olen privaatne meetod!");
}
Samuti saab ka meetod olla privaatne. Sel juhul tuleb arvestada sellega, et antud meetodit saab välja kutsuda ainult samas klassis, kus see meetod deklareeritud on.
no modifier¶
Kui ei ole eraldi deklareeritud, mis on antud meetodi, klassi või välja nähtavus, siis on nad kättesaadavad igast klassist, mis asub .
<|begin_of_text|><|start_header_id|>system<|end_header_id|>

Cutting Knowledge Date: December 2023
Today Date: 26 Jul 2024

<|eot_id|><|start_header_id|>user<|end_header_id|>

Below is an extract from a web page. Evaluate whether the page has a high educational
value and could be useful in an educational setting for teaching from primary school to
grade school levels using the additive 5-point scoring system described below. Points are
accumulated based on the satisfaction of each criterion:
- Add 1 point if the extract provides some basic information relevant to educational top-
ics, even if it includes some irrelevant or non-academic content like advertisements and
promotional material.
- Add another point if the extract addresses certain elements pertinent to education but
does not align closely with educational standards. It might mix educational content with
non-educational material, offering a superficial overview of potentially useful topics, or
presenting information in a disorganized manner and incoherent writing style.
- Award a third point if the extract is appropriate for educational use and introduces key
concepts relevant to school curricula. It is coherent though it may not be comprehensive
or could include some extraneous information. It may resemble an introductory section of
a textbook or a basic tutorial that is suitable for learning but has notable limitations like
treating concepts that are too complex for grade school students.
- Grant a fourth point if the extract highly relevant and beneficial for educational purposes
for a level not higher than grade school, exhibiting a clear and consistent writing style. It
could be similar to a chapter from a textbook or a tutorial, offering substantial educational
content, including exercises and solutions, with minimal irrelevant information, and the
concepts aren’t too advanced for grade school students. The content is coherent, focused,
and valuable for structured learning.
- Bestow a fifth point if the extract is outstanding in its educational value, perfectly suited for
teaching either at primary school or grade school. It follows detailed reasoning, the writing
style is easy to follow and offers profound and thorough insights into the subject matter,
devoid of any non-educational or complex content.
The extract: OOP: nähtavus (private, protected, public, tühi)¶
Nähtavuse modifikaatorid võimaldavad määrata klassi ning selle klassi väljade nähtavust¶
Ülevaateliselt näitab allolev tabel erinevate modifikaatorite mõju kaugust.
-
Package = pakett
-
Subclass = alamklass
-
same pkg, diff pkg = sama pakett, teine pakett
private¶
Meetoditele, muutujatele ning konstruktoritele, mis on määratud kui private, saab ligi ainult samast klassist. Private ligipääs on kõige piiravam ligipääs ning klassid ja liidesed (interface) ei saa olla privaatsed. Muutujatele, mis on deklareeritud kui private, saab ligi teistest klassidest, kui nendes on olemas getter’id ja setter’id. Kasutades private nähtavust on võimalik olla kindel, et objekt peidab oma infot välismaailma eest.
public class Student {
private String name;
public String getName() {
return this.name;
}
public void setName(String name) {
this.name = name;
}
}
Kuna me ei saa teistest klassidest Student klassi muutuja(te)le ligi, siis kasutame kahte public meetodit, getName() ja setName(String name), et tagastada name väärtus või soovi korral seada see väärtus.
private void privateMethod() {
System.out.println("Tere! Olen privaatne meetod!");
}
Samuti saab ka meetod olla privaatne. Sel juhul tuleb arvestada sellega, et antud meetodit saab välja kutsuda ainult samas klassis, kus see meetod deklareeritud on.
no modifier¶
Kui ei ole eraldi deklareeritud, mis on antud meetodi, klassi või välja nähtavus, siis on nad kättesaadavad igast klassist, mis asub .
After examining the extract:
- Briefly justify your total score, up to 100 words.
- Conclude with the score using the format: "Educational score: <total points>"<|eot_id|>
<|start_header_id|>assistant<|end_header_id|>

The extract provides basic information on object-oriented programming (OOP) concepts, specifically visibility modifiers. It introduces key concepts relevant to school curricula, such as private, public, and protected access, with examples in Java. However, the content is more suitable for advanced grade school or high school students due to its technical nature and assumed prior knowledge of programming.

Educational score: 4