Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

how to return an object in java

// Java Program to Demonstrate Objects Passing to Methods.

// Class
// Helper class
class ObjectPassDemo {
	int a, b;

	// Constructor
	ObjectPassDemo(int i, int j)
	{
		a = i;
		b = j;
	}

	// Method
	boolean equalTo(ObjectPassDemo o)
	{
		// Returns true if o is equal to the invoking
		// object notice an object is passed as an
		// argument to method
		return (o.a == a && o.b == b);
	}
}

// Main class
public class GFG {
	// MAin driver method
	public static void main(String args[])
	{
		// Creating object of above class inside main()
		ObjectPassDemo ob1 = new ObjectPassDemo(100, 22);
		ObjectPassDemo ob2 = new ObjectPassDemo(100, 22);
		ObjectPassDemo ob3 = new ObjectPassDemo(-1, -1);

		// Checking whether object are equal as custom
		// values
		// above passed and printing corresponding boolean
		// value
		System.out.println("ob1 == ob2: "
						+ ob1.equalTo(ob2));
		System.out.println("ob1 == ob3: "
						+ ob1.equalTo(ob3));
	}
}
Comment

PREVIOUS NEXT
Code Example
Java :: find subarray with given sum 
Java :: meter to cm 
Java :: java literals 
Java :: android studio tabbed activity 
Java :: types of exception in java 
Java :: nested class in java 8 
Java :: java heap example 
Java :: java check if array element is null 
Java :: minecraft addlayer(u) in the type rendererlivingentity<t is not applicable for the arguments 
Java :: Service vs IntentService. 
Java :: How do you make bedrock full screen in Minecraft? 
Java :: stream reduce stringbuilder 
Java :: reading 2d array in java 
Java :: how to declare a variable when using loops Java 
Java :: spring boot initializr-generator example 
Java :: java cambiar formato de fecha 
Java :: bukkit api listener 
Java :: Java program to print Student Info by using Class, Object, Method. 
Java :: sealed class java codegrepper 
Java :: javacal 
Java :: java object class 
Java :: SmallChange 
Java :: Android java parse class name via intent 
Java :: Java Labeled continue Statement Java 
Java :: scanner.nextInt stream api java 
Java :: import txt.xz file to android studio app 
Java :: for-each Loop Sytnax JAVA 
Java :: sfadffocusbutton 
Java :: convert text type to int java 
Java :: Join Two Variables Together In Java 
ADD CONTENT
Topic
Content
Source link
Name
3+6 =