Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating empty object in Java? [closed]

Tags:

java

object

How do you go about doing this? Is it as simple as this:

Name myName = new Name();

I'm a little confused. It should be a class with no instance variables. I simply have to "create an empty object". The constructor will also be empty of course.

like image 237
Java Newb Avatar asked Dec 26 '22 17:12

Java Newb


1 Answers

An "empty object" is pretty ambiguous in java terms. I could interpret that as this:

Object empty = new Object();

which is about the emptiest object you can create.

However in your example,

Name myName = new Name();

That's going to create an object based on whatever code you've put in your default constructor. (Which, i guess if you're setting everything to a default value, is pretty empty)

like image 106
yamafontes Avatar answered Dec 28 '22 09:12

yamafontes