60 lines
927 B
Markdown
60 lines
927 B
Markdown
<!--
|
|
title: Scope
|
|
description: Folien für Scope in Programmieren 1
|
|
url: https://git.haw-hamburg.de/pm1-tutorium/slides
|
|
header: Programmieren 1 **Tutorium**
|
|
footer: Henri Burau und Eva Meinen
|
|
-->
|
|
|
|
#scope
|
|
|
|
= Sichtbarkeit = Gültigkeitsbereich
|
|
|
|
Bereich in dem auf die Variable zugegriffen werden kann
|
|
|
|
---
|
|
|
|
```java
|
|
int zahl = 3;
|
|
addierer(zahl);
|
|
System.out.printf(zahl); // Konsolenausgabe?
|
|
public void addierer(int zahl) {
|
|
zahl++;
|
|
}
|
|
```
|
|
---
|
|
|
|
```java
|
|
public class TestFrame{
|
|
int zahl;
|
|
|
|
public void m(){
|
|
zahl = 3;
|
|
}
|
|
public void m2(){
|
|
System.out.printf(zahl);
|
|
}}
|
|
```
|
|
|
|
---
|
|
```java
|
|
public class TestFrame {
|
|
public int num;
|
|
|
|
public void m(int zahl){
|
|
System.out.printf("1. %d %n", num);
|
|
num++;
|
|
int num = 4;
|
|
System.out.printf("2. %d %n", num);
|
|
num++;
|
|
System.out.printf("3. %d %n", num);
|
|
}
|
|
public void m2(){
|
|
num = 3;
|
|
System.out.printf("4. %d %n", num);
|
|
m(3);
|
|
System.out.printf("5. %d %n", num);
|
|
}}
|
|
```
|
|
|