Quantcast
Channel: Define constructor in Java - Stack Overflow
Browsing all 5 articles
Browse latest View live

Answer by Luke Melaia for Define constructor in Java

Of corse you can write a constructor for Main. Any class, enum and abstract class can have a constructor. Simple usagepublic Main(){ //Constructor code here...}Then to call main just use:Main main =...

View Article



Answer by Ankur Singhal for Define constructor in Java

I would like to know how can I define constructor in Java. I started writing piece of code but I get errors.Error is because constructor is defined inside main() method. Need to move outside. You can...

View Article

Answer by Stanislav for Define constructor in Java

Your constuctor must be like any other method declared (but it has to be called same, as the class name, and do not provide any return):public class ConstructorExample { //this is your class fieald...

View Article

Answer by Parker_Halo for Define constructor in Java

You cannot define a Constructor inside a method. You have to declare it like any other method in the class body.package xyz;public class ConstructorExample { public ConstructorExample(int x,int y){//...

View Article

Define constructor in Java

I would like to know how can I define constructor in Java.I started writing piece of code but I get errors.package xyz;public class ConstructorExample { public static void main(String[] args) { public...

View Article

Browsing all 5 articles
Browse latest View live




Latest Images