Java-Default Value of Class Members

Default Value of Class Members The member variable is declared but not defined, it is always default-initialized to a zero of the appropriate. Following table shows variables types and their default values : Data Type Default value char 0 int / short / long / byte 0 float / double 0.0 String null Program Program Source class Data{ byte byt; int … Read more…

Java-Assigning Object Reference

Assigning Object Reference We are assign one object reference variable to another object reference variable, we are not creating a copy of the object, we are only making a copy of the reference. For example, in the following program, the object references d1, d2 and d3 will point to the same object. Therefore, any change … Read more…

Java-Constructor

Constructor Java provides a special construct named constructor exclusively for creating an object of a and initializing its instance variables. Constructor look like methods but aren’t. The constructor  has the same name as the class and has no return type specified. Once defined, the constructor is automatically called immediately after the object is created, before … Read more…

Java-Constructor with Parameter

Constructor with Parameter A constructor is have parameters is known as parameterized constructor. A constructor can take zero, one, or more parameters. Program Program Source class Data{ int data; Data(int d) { data = d; } void printData() { System.out.println(“data : “+data); } } public class Javaapp { public static void main(String[] args) { Data … Read more…

Java-Constructor Overloading

Constructor Overloading A class shall have several constructors, provided they have different signatures. As we know, the signature of a constructor is a combination of its name and the sequence of its parameter types. The names of all the constructors of a class should be same as the name of that class. Therefore the overloaded … Read more…

Java-Private Access Specifier

Private Access Specifier Variables are generally declared with the access control modifier private. In such a case, they can be accessed only by methods of the class in which they are defined. This is the highest degree of protection. In the following program, the variable privateData can be accessed only by methods of the class … Read more…