BAEL-2472 code examples

This commit is contained in:
jose 2019-01-08 23:55:48 -03:00
parent 3da571a218
commit 065a6e2519
5 changed files with 76 additions and 0 deletions

View File

@ -0,0 +1,15 @@
package org.baeldung.variable.scope.examples;
public class ClassScopeExample {
Integer amount = 0;
public void exampleMethod() {
amount++;
}
public void anotherExampleMethod() {
amount--;
}
}

View File

@ -0,0 +1,18 @@
package org.baeldung.variable.scope.examples;
import java.util.Arrays;
import java.util.List;
public class LoopScopeExample {
List<String> listOfNames = Arrays.asList("Joe", "Susan", "Pattrick");
public void iterationOfNames() {
String allNames = "";
for (String name : listOfNames) {
allNames = allNames + " " + name;
}
}
}

View File

@ -0,0 +1,16 @@
package org.baeldung.variable.scope.examples;
public class MethodScopeExample {
Integer size = 2;
public void methodA() {
Integer area = 2;
area = area + size;
}
public void methodB() {
size = size + 5;
}
}

View File

@ -0,0 +1,13 @@
package org.baeldung.variable.scope.examples;
public class NestedScopesExample {
String title = "Baeldung";
public void printTitle() {
System.out.println(title);
String title = "John Doe";
System.out.println(title);
}
}

View File

@ -0,0 +1,14 @@
package org.baeldung.variable.scope.examples;
public class OutOfScopeExample {
public void methodWithAVariableDeclaredInside() {
String name = "John Doe";
System.out.println(name);
}
public void methodWithoutVariables() {
System.out.println("Pattrick");
}
}