moving basicmethods from oop-2 to oop-3 (#7827)
This commit is contained in:
committed by
KevinGilmore
parent
9baee5bc6e
commit
c1caed8dde
@@ -0,0 +1,37 @@
|
||||
package com.baeldung.basicmethods;
|
||||
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
|
||||
public class PersonName {
|
||||
|
||||
public String getName(String firstName, String lastName) throws RuntimeException {
|
||||
return firstName + " " + lastName;
|
||||
}
|
||||
|
||||
public String getName(String firstName, String middleName, String lastName) {
|
||||
if (!middleName.equals("")) {
|
||||
return firstName + " " + lastName;
|
||||
}
|
||||
return firstName + " " + middleName + " " + lastName;
|
||||
}
|
||||
|
||||
public void printFullName(String firstName, String lastName) {
|
||||
System.out.println(firstName + " " + lastName);
|
||||
}
|
||||
|
||||
public void writeName(String name) throws IOException {
|
||||
PrintWriter out = new PrintWriter(new FileWriter("OutFile.txt"));
|
||||
out.println("Name: " + name);
|
||||
out.close();
|
||||
}
|
||||
|
||||
public static String getNameStatic(String firstName, String lastName) {
|
||||
return firstName + " " + lastName;
|
||||
}
|
||||
|
||||
public static void callToStaticMethod() {
|
||||
System.out.println("Name is: " + PersonName.getNameStatic("Alan", "Turing"));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user