This commit is related to BAEL-7028 (#15648)
This commit aims to add two classes: - PrintMessageWithoutMainMethod - PrintMessageWithoutMainUnitTest
This commit is contained in:
parent
6818b14f15
commit
85c4162119
|
@ -0,0 +1,33 @@
|
|||
package com.baeldung.printmessagewithoutmain;
|
||||
|
||||
public final class PrintMessageWithoutMainMethod {
|
||||
|
||||
//Using Static Blocks
|
||||
static {
|
||||
System.out.println("Hello World!!");
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
//Using Nested Classes
|
||||
static {
|
||||
NestedClass.printMessage();
|
||||
}
|
||||
|
||||
//Executing Code During Class Initialization
|
||||
private static final int STATUS = getStatus();
|
||||
private static int getStatus() {
|
||||
System.out.println("Hello World!!");
|
||||
System.exit(0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
}
|
||||
|
||||
static class NestedClass {
|
||||
static void printMessage() {
|
||||
System.out.println("Message from nested class");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
package com.baeldung.printmessagewithoutmain;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class PrintMessageWithoutMainUnitTest {
|
||||
@Test
|
||||
public void givenMessage_whenUsingJunitTest_thenPrintMessage() {
|
||||
System.out.println("Hello World!!");
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue