Java-Returning Objects

Returning Objects A method can return any type of data, including class types that you create. For example, in the following program, the createData( ) method returns an object of Data. Program Program Source class Data { int data1; int data2; } class CreateData { Data createData() { return new Data(); } } public class … Read more…

Java-Objects as Parameters

Objects as Parameters A method can take an objects as a parameter. For example, in the following program, the method setData( ) takes three parameter. The first parameter is an Data object. If you pass an object as an argument to a method, the mechanism that applies is called pass-by-reference, because a copy of the reference … 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-Declaring Objects

Declaring Objects An object is an instance of a class. The relationship is such that many objects can be created using one class. Each object has its own data but its underlying structure are defined by the class. There are two steps when creating an object from a class : Declaration A variable declaration with a … Read more…