@@ -49,7 +49,7 @@ are all optional.
4949
5050{% highlight java linenos %}
5151
52- class Animal {
52+ public class Animal {
5353}
5454
5555class Horse extends Animal {
@@ -108,7 +108,7 @@ __The 3 factors that can make overloading a little tricky _(written in order of
108108
109109{% highlight java linenos %}
110110
111- class MethodOverloading {
111+ public class MethodOverloading {
112112
113113 static void go(float x) {
114114 System.out.print("float ");
@@ -176,7 +176,7 @@ code:
176176
177177{% highlight java linenos %}
178178
179- class Animal {
179+ public class Animal {
180180 static void eat() {
181181 }
182182}
@@ -204,7 +204,7 @@ Let's see what happens when the compiler has to widen and then autobox the param
204204
205205{% highlight java linenos %}
206206
207- class WidenAndBox {
207+ public class WidenAndBox {
208208 static void go(Long x) {
209209 System.out.println("Long");
210210 }
@@ -231,7 +231,7 @@ Now let's see another program when the compiler has to autobox and then widen th
231231
232232{% highlight java linenos %}
233233
234- class BoxAndWiden {
234+ public class BoxAndWiden {
235235 static void go(Object obj) {
236236 Byte b2 = (Byte) obj; // ok - obj refers to a Byte object
237237 System.out.println(b2);
@@ -256,7 +256,7 @@ __Combine both Widening and Boxing with Var-args__
256256
257257{% highlight java linenos %}
258258
259- class Vararg {
259+ public class Vararg {
260260
261261 static void wide_vararg(long... x) {
262262 System.out.println("long...");
@@ -266,10 +266,15 @@ class Vararg {
266266 System.out.println("Integer...");
267267 }
268268
269+ static void box_widen_vararg(Object... x) {
270+ System.out.println("Object...");
271+ }
272+
269273 public static void main(String[] args) {
270274 int i = 5;
271275 wide_vararg(i, i); // needs to widen and use var-args
272276 box_vararg(i, i); // needs to box and use var-args
277+ box_widen_vararg(i, i); // needs to box and then widen and finally use var-args
273278 }
274279}
275280
@@ -279,6 +284,7 @@ The above code compiles fine and produces the output:
279284
280285 long...
281286 Integer...
287+ Object...
282288
283289From the result, its clear that we can __ successfully combine var-args with either widening or boxing__ .
284290
0 commit comments