0% found this document useful (0 votes)
24 views1 page

Java Video

The document discusses constructors in Java, explaining that they are methods with the same name as the class, are always public, initialize memory for objects, and are called automatically when an object is created. It also covers constructor overloading, using the 'this' keyword to differentiate between parameters and instance variables, and static methods which are shared across all objects of a class.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views1 page

Java Video

The document discusses constructors in Java, explaining that they are methods with the same name as the class, are always public, initialize memory for objects, and are called automatically when an object is created. It also covers constructor overloading, using the 'this' keyword to differentiate between parameters and instance variables, and static methods which are shared across all objects of a class.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

Constructor:

* It is method of a cls
* it has same name of a cls with brackets.
* constructor never reuturn anything so it is public always.
* every time when we need to creaqte object then we will use consructor.
* even if we don't construct constructor the constructor will be there and this is
called default constructor.
* It is used to alloct memory for object.
* when we create an object it will call constructor so we don't need to call
constructor again.
constructor overloading:
it is having diff types of constructors with diff types of parameters.
* when we are passing float value will will pass the no with f for ex:5.5f,..

*** we use ""this"" variable to access the instance variable..i.e., when we create
a constructor with parameers and if the parameters and instance(the variables
outside the constructor)variables are same then to access those variables we will
use this variable to instance variables.

Static method:

* If a variable is static then it same for all objects.


* When the variable is static then the name of the can either be object name or cls
name.
* In static the cls will load only once.

You might also like