by Dinesh Thakur Category: Classes

Sometimes a programmer wants to create an exact but separate copy of an existing object so that subsequent changes to the copy should not alter the original or vice versa. This is made possible using the copy constructor.

 
by Dinesh Thakur Category: Classes

When values of built in types are passed as arguments to a function. It is known as Call by value. The changes made to formal parameters in the called function are not reflected in the actual arguments class.

 
by Dinesh Thakur Category: Classes

In this Java Example we declares a class named Rect. It contains two integer member variables, l and b (for length and breadth). Since no access specifier is used, these variables are considered public. Public means that any other class can freely access these two members.

 
by Dinesh Thakur Category: Classes

In this example, we compute the electricity bill of a particular customer. The class ElectricityBil1 contains field customerNo, name and units. It also contains methods setData () show () and billcalculate ().The statement,

 
by Dinesh Thakur Category: Classes

Compile Time Polymorphism in Java is when you have the several methods with same name and different parameters and compiler has to decide how to select which method has to run based on the arguments hence the name Compile time polymorphism or method overloading.

 
by Dinesh Thakur Category: Classes

Unlike default constructor which do not have any parameters, it is however possible to have one or more parameters in a constructor. This type of constructor which have parameters is known as parameterized constructor. Using parameterized constructor, it is possible to initialize objects with different set of values at the time of their creation. These different set of values initialized to objects must be passed as arguments when constructor is invoked. The parameter list can be specified in the parentheses in the same way as parameter list is specified in the method.

 
by Dinesh Thakur Category: Classes

Constructors are the methods having the same name as that of the class and are automatically executed on defining an object. The main purpose of a constructor is to initialize a new object.

Java does not allocates memory for objects at application startup time but rather when the instance is created by keyword new. When new is invoked, Java allocates enough memory to hold the object and then initializes any instance variables to default values.

 
by Dinesh Thakur Category: Classes

Constructor Overloading means a class having multiple constructors with the same name, but with different number of arguments or different type of arguments. The compiler differentiates the constructors based on the number of parameters in the list and their types. That means, on the basis of the number and type of the arguments that we pass into the constructor, the compiler determines which constructor to call.

 
by Dinesh Thakur Category: Classes

This example is used to calculate the area and circumference of a circle with given radius. The class Circle contains the field radius and methods setData (), area ()and circumference ().The statement.

 

Page 1 of 6



About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.SC (Computer Science), MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.



Related Articles