answersLogoWhite

0


Best Answer

Depends on the language. For Java, yes.

User Avatar

Wiki User

12y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Can the return type of a method be an array?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

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 array list a value type or reference type?

Array lists are objects and are of the reference data types. If you pass an array list from a java method to another as an argument, you need not return this from the target method because the modifications to the list would be happening in its value and hence would be available in the parent or calling method without being received as an output from the called method.


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.


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.


What is return type of string in c?

In C programming, a string doesn't have a specific return type as it's essentially an array of characters. So, if a function is returning a string, it should be declared to return a pointer to a char (char*), since a string in C is represented as an array of characters terminated by a null character ('\0').

Related questions

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 array list a value type or reference type?

Array lists are objects and are of the reference data types. If you pass an array list from a java method to another as an argument, you need not return this from the target method because the modifications to the list would be happening in its value and hence would be available in the parent or calling method without being received as an output from the called method.


Write a function in java that accepts an array of integers and returns the second largest integer in the array Return -1 if there is no second largest?

Method 1: Sort the array in descending order, compare 1st and 2nd if not same , return 2nd if same return -1 Method 2: Find the largest number in the array, initialize another array with dimension 1 less than of original. Copy the array elements from the original array minus the largest element. not select largest from the second array and compare with the previous one if not same return the second largest if same return -1


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 the return type of finally method in java?

The final and finally keywords have no impact on the return type of a method in Java.


What is default return type for method in java?

default return type is : true


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.


What is return type of string in c?

In C programming, a string doesn't have a specific return type as it's essentially an array of characters. So, if a function is returning a string, it should be declared to return a pointer to a char (char*), since a string in C is represented as an array of characters terminated by a null character ('\0').


How do you write method pubic boolean containsString s Return whether the given string is in the array or not?

Return an iterator to the string if it exists, or the container's end iterator if it does not.


Difference in using a method that return value and method that does not return value in object orinted programming?

A method that return a value should have a return statement. The method signature should indicate the type of return value. While in the case of a method that does not return a value should not have a return statement and in the signature, the return type is void. When using a method that doesn't return a value, a programmer can not get a value from that function, but instead, it can only change variable values and run other methods.


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.


Which of these is an access modifier for a method - void protected int or main?

* void - This is a return type - or, more correctly, specifies that a method has no return type.* protected - This is an access modifier. It says that the only classes that can call this method are subclasses and classes in the same package.* int - This is a value type (or return type).* main - This is the name of the method.