answersLogoWhite

0

What is return data type?

Updated: 8/10/2023
User Avatar

Wiki User

9y ago

Best Answer

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.

User Avatar

Wiki User

13y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What is return data type?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

What is returntype?

A return type describes the type of data which is returned by a call to a method. They keyword void is used to describe a method which does not return any data.


What are the valid type of data that the main can return in c language?

Type 'int'


What TYPES of return values are allowed?

Apart from basic Data types (int , char , float and double ) you can even return Class Objects.Nearly any type of Data can be returned by a function including pointers to void data type.


What part of a function definition specifies the data type of the value that the function returns?

The function header. The return value is written before the name of the function. This return type must match the type of the value returned in a return statement.


What use of void data type in c plus plus?

doesn't return the value.


Why the return type of all the function by default is int in c?

Because int is the most common data-type in C. Don't rely on this though, always specify the return type explicitly.


Why do you use a void pointer in a programme?

void is type of pointer that usually means that you can make it point to any data type. When you make a pointer point to somewhere its data type should match with the place where you want it to point. When you dont know the data type where it will point to then you can declare a void pointer and make it point to the data type it want.


What data type does the main function return in c?

The main function must return the int data type. A program that terminates normally should return the value zero to indicate no error. Not all execution environments make use of the return value (Windows in particular), however a command script or batch file can examine the ERRORLEVEL if required.


How can you return an array from a method in Java?

You can do this by returning it just like any other data type. int[] f() { return new int[0]; }


Is 'void' a data type in java?

No. The void keyword is used to signify that a method will not return any objects. For example, if you type in "double", you'll need a return statement that has a double. So "void" means that there will be nothing returned.


What do parameters and return values have to do with methods?

Parameters and return values are a major part of methods. When defining a method, you must include information about the data types of the return value and the parameters. An example of a method definition is this: public int getSumOfNumbers( int number1, int number2, int number3 ) { return ( number1 + number2 + number3 ); } The word "int" right after the word "public" is the return type. It describes what data type will be returned by the method. In this case, it was int, or integer. The sequence of words in between the parantheses, "int number1, int number2, int number3", is the parameter list. Each of the phrases separated by a comma in the parameter list is a parameter. The first word - in this case "int" - is the data type of the parameter. It describes what type of variable the parameter will be. The second word - "number1", "number2", or "number3" - is the name of the parameter. Every parameter must have a data type and a name, and every method must have a return type: even a method that returns nothing. For example: public void evaluateNumber(int number) { if ( number > 0 ) { System.out.println( number + " is positive." ); } else if ( number < 0 ) { System.out.println( number + " is negative." ); } else { System.out.println( number + " is zero." ); } } When a method does not return data, its return type must be defined as void, as it is above.


Why use void in main of java?

No. void is not a data type. It is mandatory for all java methods to return something and if it is not going to return anything, we have to mark the method with a "void" return type to let the JVM know that it must not expect anything from the method.