diff --git a/core-java/src/main/java/com/baeldung/polymorphism/GenericFile.java b/core-java/src/main/java/com/baeldung/polymorphism/GenericFile.java index 4075083c49..03e704f36f 100644 --- a/core-java/src/main/java/com/baeldung/polymorphism/GenericFile.java +++ b/core-java/src/main/java/com/baeldung/polymorphism/GenericFile.java @@ -54,7 +54,7 @@ public class GenericFile { } public String getFileInfo() { - return "File Name: " + this.getName() + "\n" + "Extension: " + this.getExtension() + "\n" + "Date Created: " + this.getDateCreated() + "\n" + "Version: " + this.getVersion() + "\n"; + return String.format("File Name: %s\n" + " Extension: %s\n" + " Date Created: %s\n" + " Version: %s\n", this.getName(), this.getExtension(), this.getDateCreated(), this.getVersion()); } public Object read() { diff --git a/core-java/src/main/java/com/baeldung/polymorphism/ImageFile.java b/core-java/src/main/java/com/baeldung/polymorphism/ImageFile.java index ac72a40993..e237f3f826 100644 --- a/core-java/src/main/java/com/baeldung/polymorphism/ImageFile.java +++ b/core-java/src/main/java/com/baeldung/polymorphism/ImageFile.java @@ -30,7 +30,7 @@ public class ImageFile extends GenericFile { } public String getFileInfo() { - return super.getFileInfo() + "Height: " + this.getHeight() + "\n" + "Width: " + this.getWidth(); + return String.format(" %s Height: %d\n Width: %d", super.getFileInfo(), this.getHeight(), this.getWidth()); } public String read() { diff --git a/core-java/src/main/java/com/baeldung/polymorphism/TextFile.java b/core-java/src/main/java/com/baeldung/polymorphism/TextFile.java index 8280b4ee95..2c28c968b8 100644 --- a/core-java/src/main/java/com/baeldung/polymorphism/TextFile.java +++ b/core-java/src/main/java/com/baeldung/polymorphism/TextFile.java @@ -21,7 +21,7 @@ public class TextFile extends GenericFile { } public String getFileInfo() { - return super.getFileInfo() + "Word Count: " + wordCount; + return String.format(" %s Word Count: %d", super.getFileInfo(), wordCount); } public String read() { diff --git a/core-java/src/test/java/com/baeldung/polymorphism/PolymorphismUnitTest.java b/core-java/src/test/java/com/baeldung/polymorphism/PolymorphismUnitTest.java index 8fb606c2fc..58826766e0 100644 --- a/core-java/src/test/java/com/baeldung/polymorphism/PolymorphismUnitTest.java +++ b/core-java/src/test/java/com/baeldung/polymorphism/PolymorphismUnitTest.java @@ -3,8 +3,6 @@ package com.baeldung.polymorphism; import static org.junit.Assert.*; import java.awt.image.BufferedImage; - -import org.junit.Ignore; import org.junit.Test; public class PolymorphismUnitTest {