这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions core-java-modules/core-java-25/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,4 @@
</plugin>
</plugins>
</build>

</project>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.baeldung.flexibleconstructorbodies;

public class Coffee {

int water;
int milk;

public Coffee(int water, int milk) {
this.water = water;
this.milk = milk;
}

public int getTotalVolume() {
return water + milk;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.baeldung.flexibleconstructorbodies;

public class SmallCoffee extends Coffee {

String topping;

public SmallCoffee(int water, int milk, String topping) {
int maxCupVolume = 100;
int totalVolume = water + milk;
if(totalVolume > maxCupVolume) {
throw new IllegalArgumentException();
}
this.topping = topping;
super(water, milk);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import static org.junit.jupiter.api.Assertions.assertEquals;

import org.junit.Test;

import com.baeldung.flexibleconstructorbodies.SmallCoffee;

public class FlexibleConstructorBodiesTest {

@Test
public void test() {
SmallCoffee smallCoffee = new SmallCoffee(30,40, "none");
assertEquals(70, smallCoffee.getTotalVolume());
}

}