Actually I have two questions
1) Why we not create Object with simple mathod like [(class name) (object name;)] in java
2) Why we use Constructor to create object code below

class Run{}
 Run obj=new Run()

why not use this code
Run obj=new Run;
Please relese my confusion

Re: Using Constructor For Creating Object in java 80 80

because Java is a language with it's own syntax. the way you suggest wouldn't compile.
neither would the first, btw, you need to add a ';'
Run obj = new Run;
if this was valid, what if your class had two constructors? the jvm needs to know what it is you are trying to do, and for methods and constructors, it expects a list of parameters, which can go from 0 to ....
those, you put between the '()'

Re: Using Constructor For Creating Object in java 80 80

1) because java has its own syntax that has to be followed upon object creation
2) because you can initialize your class i nthe constructor so whenever you create an object of that class, it will already have assigned parameters and be ready to use(for example GUI's)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.19 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.