Moving classes into core-java-lang

This commit is contained in:
jose 2019-01-24 23:06:51 -03:00
parent 4c540b764c
commit ca5ff8ac8c
5 changed files with 71 additions and 0 deletions

View File

@ -0,0 +1,14 @@
package org.baeldung.variable.scope.examples;
public class BracketScopeExample {
public void mathOperationExample() {
Integer sum = 0;
{
Integer number = 2;
sum = sum + number;
}
// compiler error, number cannot be solved as a variable
// number++;
}
}

View File

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

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;
}
// compiler error, name cannot be resolved to a variable
// String lastNameUsed = name;
}
}

View File

@ -0,0 +1,13 @@
package org.baeldung.variable.scope.examples;
public class MethodScopeExample {
public void methodA() {
Integer area = 2;
}
public void methodB() {
// compiler error, area cannot be resolved to a variable
// area = area + 2;
}
}

View File

@ -0,0 +1,12 @@
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);
}
}