Can you declare an instance variable as a parameter in a constructor?

后端 未结 3 452
面向向阳花
面向向阳花 2021-01-24 03:41

Would this work?

class Cars{
    Cars(int speed, int weight)
}

I am just trying to figure out the constructor. If it is called like a method t

3条回答
  •  执笔经年
    2021-01-24 04:19

    You are probably not understanding the correct use of Constructors.
    

    Constructor

    A constructor is used in the creation of an object that is an instance of a class. Typically it performs operations required to initialize the class before methods are invoked or fields are accessed.

提交回复
热议问题