For example if I were to create the following class:
public Class ExampleClass {
private static String field1;
private String field2;
public ExampleClass(String field2) {
this.field2 = field2;
}
public static staticMethodExample(String field1) {
this.field1 = field1;
}
}
If I were to create an instance of ExampleClass
. Would that instance contain the code for the static method and/or field I created?
I have an object that will represent some data from a row in my database. I would like to create the a list of these objects from every row in the database. The database has thousands of rows. The static methods I am creating will format the values from the database before putting them into the objects constructor.
I don't want to bloat the code by having the method stored in every instance of the object. So if static methods do take up space in every instance of an object, then I would much rather create a separate class of of a name like ExampleClassBuilder
. And put the formatting static methods in there.