Thursday, May 6, 2021

CONSTRUCTOR or FINAL KEYWORD (Experience In JAVA)

CONSTRUCTOR

Constructor is a special type of member function which name is the same as that class which contents it. It does not have any return type even void it must be public. It is used to initializes the required data members of the class.

It is automatically called when we create the object of the class.

There are three types of the constructor.

1. Default constructor

The constructor has which does not have any parameter us known as default constructor.


2. Parameterized constructor

The constructor which having a set of the variable of the parameter is known as parameter constructor.

3.Copy constructor

The constructor which having a set of the object as the parameter is known as copy constructor.



Final Keyword

Final is a special type of keyword which is used to make following
  • Class Final 
  • Method Final
  • Field Final
  • Object Final

1.Class Final

When you declared a class as the final class then you cannot extend or inherits that class. That means the final classes are fixed classes that cannot be inherited but can be instantiated.
Example:


2.Method final

If we declared a method as a final method then we cannot change the implementation of that method.

Example.


3.Field Final.

If we declared a field as a final field then we cannot change the value of that field throughout the program. In java final field is equivalent to the constant of c /c++.

Example.

4.Object Final.

If we declared an object as a final object then we cannot change their reference once allocated.

Example.


No comments:

INTRODUCTION TO COMPUTER NETWORKS

A Computer network consists of two or more autonomous computers that are linked (connected) together in order to: • Share resources (files...