answersLogoWhite

0


Best Answer

Functions and Constructors are similar in many ways. They can have arguments, they can have any amount of code, they can access the class's variables etc. the only difference is that a method in java needs to mandatorily have a return type but 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
More answers
User Avatar

Learn bay

Lvl 8
2y ago

Constructor is a block of code that initializes a newly created object. Function is a group of statements that can be called at any point in the program using its name to perform a specific task. Constructor has the same name as class name.

To learn more about data science please visit- Learnbay.co

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What is the difference between consructor and function in java?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

What is the difference between method and function in java?

A function is a piece of code that can be reused by calling its name while a method is a function that is associated with a class. In Java, functions are usually referred to as static methods.


Difference between procedure and function in C or C plus plus or Java language?

In C there are functions only, In Java methodsonly (static methods as well), in C++ both.


What is difference between java 2 and java 5?

They are different versions. Java 5 is newer than Java 2. Think of it like the difference between the Playstation 1 and the Playstation 3.


Major difference between c and java?

Java is object oriented, C is not...


What is the difference between connectivity in java?

kamina


What is difference between connectivity in java?

kamina


What is the main difference between UNIX and JAVA?

Unix is an operating system, Java is a language.


Difference between recordset and resultset in java?

Rowset


What is the difference between JAD and JAR?

JAD-Java Application Description JAR-Java archive


What is the difference between java and object oriented programming?

java is a programming language/platform that embodies object oriented programming concepts. The question of what is the difference is like asking what is the difference between cars and a Volvo.


What is the difference between c plus plus and java programming?

Java doesn't have pointers. C++ has pointers.


What difference between InputStreamReader and DatainputStream in java?

Both are same