Computer Science, asked by gotnwkira, 10 months ago

Can constructors be used as normal methods in java (and not just for initializing the instance variables)

Answers

Answered by reenajuglan2012
1

Explanation:

Constructor is a block of code that initializes the newly created object. A constructor resembles an instance method in java but it’s not a method as it doesn’t have a return type. In short constructor and method are different(More on this at the end of this guide). People often refer constructor as special type of method in Java.

Constructor has same name as the class and looks like this in a java code.

public class MyClass{

//This is the constructor

MyClass(){

}

..

}

Note that the constructor name matches with the class name and it doesn’t have a return type.

hope it helps

pls mark as brainlist ans plssss

..

Similar questions