Java Complete Course: 13: Constructors

Поділитися
Вставка
  • Опубліковано 18 жов 2024

КОМЕНТАРІ • 3

  • @Denge-dq1qr
    @Denge-dq1qr 2 місяці тому

    Constructor is block of code similar to a method that's called when instance of an object is created .The work is to initialize the new created object.constructor must have same name with class ,has no return type and constructor is invoked when a new object is created using new keywords.this keyword is used constructor to refer to the current instance of the class.

  • @sykesalex
    @sykesalex 2 місяці тому

    constructors initialize objects immediately when are created and they don’t have return type because what they are returning is the implicit return type of the class. also use the keyword “this.” to refer to the object that invoked the method. Instance variable hiding happen in cases where the local variable has the same name as instance variable and java hides the instance variable.

  • @kibascarlett9179
    @kibascarlett9179 Місяць тому

    I learnt constructors meaning which is they Initialize objects immediately it is created. It has the same name with the class and is of the same syntax as the method. They don’t have return type because what they are returning is the implicit return type of the class. Java creates a default constructor for the class and initializes the instance variables to 0 when the programmer fails to define their own constructor. Such a case is not proper if the programmer needs to create complicated classes. We can also use the keyword “this.” to refer to the object that invoked the method. Instance variable hiding happen in cases where the local variable has the same name as instance variable and java hides the instance variable. Garbage collection in java is when there is no reference to an object in the program and java takes it as though the object is no longer needed and as a result it destroys that object to free the space for more operations. Finalize () method holds that object just before the object is destroyed by garbage collector.