ruby - How to avoid implicit call to parent class's constructor in Java? -
I have this code which is I compare Java with ruby due to my small risk to do this. In Ruby, the parent's constructor is called only when the child is not one, therefore, I am trying to achieve my basic rights. The only way to avoid an inherent call to a parent's creator A clear call to a parent creator You can not refrain from calling the Constructor for each class. BTW does not require you to store object creation object should be avoided should be about to start. Side Effects. "a tree" twice and
"oak tree Prints " Once I think that it's saying the
tree class constructor inherently extends the
public class app {public static zero main (string [] args) {tree p = new tree (); Oak m = new oak (); }} Public square tree {the name of the protected string; Public tree () {name = "A tree"; Println (name); }} Public square oak tree {public string name = "an oak tree" is extensively; Public Oak () {System.out.println (name); }}
class CDEF starts "C class" and end class D & LT; "D Class" End End # Class E does not have its own Constructor Class of CDR initialization E & lt; C end CNU # = & gt; C Class D.N. # = & gt; Dee Class E.new # = & gt; C class
name twice a simple approach is to do the following.
public square tree {name of protected string; Public tree (this ("a tree");} protected tree (string name) {this.name = name; Println (name);}} public square oak tree (public oak) (super "(an oak tree" ) Is spread;}} In Java, it is believed that there is no sensible reason to call the constructor for a given class. If you think that this is a The problem is, you are doing things in your constructor that is more than just making and Ncniy side effects.
Comments
Post a Comment