How does Java choose which constructor to use?

后端 未结 2 1445
甜味超标
甜味超标 2020-12-20 14:26

I am not able to understand the output of the following program.

public class Confusing {

    private Confusing(Object o) {
        System.out.println(\"Obj         


        
相关标签:
2条回答
  • 2020-12-20 15:10

    The challenge of compiling dynamically typed languages is how to implement a runtime system that can choose the most appropriate implementation of a method or function — after the program has been compiled. Treating all variables as objects of Object type would not work efficiently.

    Hence, choosing the specific one over Object.

    0 讨论(0)
  • 2020-12-20 15:20

    Even though both constructors can accept null, double[] inherits from java.lang.Object, and is therefore more specific.

    0 讨论(0)
提交回复
热议问题