answersLogoWhite

0

How do you return an object in java?

Updated: 8/20/2019
User Avatar

Wiki User

11y ago

Best Answer

With the command return, followed by an object variable. In the method header, you have to declare the return type as the class of the object.

User Avatar

Wiki User

11y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How do you return an object in java?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

How do you search for an object in a list and if matches return that object using java?

Using boolen Contains(Object ob) method of List Interface .we can find object through List....


How many values can a method return in Java?

A method in java can declare only one return value and type at a time. For ex: a single method cannot have a code that returns a string in some cases and an integer in other cases. Java compiler does not let you do that. You can only have one return type for every method in java.


What is a java object?

A java object is a collection of methods and properties defined in the Java programming language.


What language is completely object oriented c plus plus or java?

Java is the complete object oriented Programming Language as every thing in java is an object,


Why constructor in Java doesn't have any return type?

The constructor of a Java class is not an ordinary method. Its purpose is not to return any value. The purpose of the constructor is to instantiate the class which it does. Since, the purpose of a constructor is only to instantiate and initialize its class and not anything else, it does not have a return type. All it does is creates an object of that class.


Can you initialize an object without constructor in java?

No. if you wish to create an object that you plan on using in a java program then the answer is NO. You cannot initialize an object of a Java class without calling the constructor.


What are impure functions in Java?

Pure functions are those which do not modify the state of an object. Most often these are functions which take arguments and return a result.


Did java oriented language works on object?

Java is an object oriented language, and it works with classes and objects.


Why do you require a object in java but not in C?

Because Java is an object-oriented language and C is a procedural language.


Is there class name as object in java?

Yes, the base class for all other Java classes is Object.


What is return data type?

A Constructor in java cannot have a return type. It always creates and returns an object of the class for which it is the constructor. You cannot return a value from a constructor explicitly and if you try to do that, the compiler will give an error. The system knows that the purpose of the constructor is to create an object of the class and it will do the same irrespective of whether you declare a return type or not.


Why java is certifiction?

java is a object oriented langage,that is indepentant platform. java is full object oriented language. java is access any operating system.so java is good certification of program in runtime environment.