Getting Started with Basic Java Constructors



Constructor :-

        In Java, a class instance is created using the constructor. With the exception of having no return type and having the same name as the class, constructors are nearly identical to methods. In java programming, constructor run first. 

              



        1. Parameterless Constructor

                     Parameter-less constructors are those that are defined without any arguments or parameters. The operation of a parameter-less constructor is similar to that of a default constructor; it might be empty or contain statements.



       1. Parameterized Constructor

                In Java programming, parameterized constructors are constructors that have one or more arguments and are written by programmers for a class. When creating user instances of objects with user-defined states, parameterized constructors come in handy. In classes, parameterized constructors can exist in several instances.













Comments

Popular posts from this blog

අද අපි කතා කරමු Data collections ගැන

Understanding and Mastering Coding Errors

OOP key points