Friday, March 20, 2020

John Dillinger essays

John Dillinger essays On June 22, 1903 a man named John Dillinger was born. He grew up in the Oak Hill Section of Indianapolis. When John was three years old his mother died, and when his fatehr remarried six years later, John resented hes stepmother. When John was a teenager he was frequently in trouble. He finally quit school and got a job in a machine shop in Indianapolis. He was very intelligent and a good worker, but he soon got bored and often stayed out all night. His father began to think that the city was corrupting his son, so he sold his property in Indianapolis and moved his family to a farm near Mooresville, Indiana. John reacted no better to rural life than he had to that in the city and soon began to run wild again. At the age of 21 he attempted his first robbery, robbing a grocery store, in his home town. He was caught and imprisoned for nine years until 1933. Soon after he was released, Dillinger robbed a bank in Bluffton, Ohio and was arrested by the Dayton police. He was put in Lima county jail to wait for his trial. The Lima police found a document on John which seemed to be a plan for a prison break, but he denied everything. Four days later, using the same plans, eight of Dillinger's friends escaped from the Indiana State Prison, using shotguns and rifles which had been smuggled into their cells. During their escape, they killed two guards. On October 12, three of the escaped prisoners and a parolee from the same prison showed up at the Lima jail where Dillinger was. They told the sheriff that they had come to return Dillinger to the Indiana State Prison for violation of his parole. When the sheriff asked to see their credentials, one of the men pulled a gun, shot the sheriff and beat him into unconsciousness. They took the keys, freed Dillinger, locked the sheriff's wife and a deputy in the cell, and left. Leaving the sheriff to die on the floor. These four mens fingerprint cards were pulled, indicating that they were w ...

Tuesday, March 3, 2020

Implicit and Explicit Constructor Chaining

Implicit and Explicit Constructor Chaining Constructor chaining in Java is simply the act of one constructor calling another constructor via inheritance. This happens implicitly when a subclass is constructed: its first task is to call its parents constructor method. But programmers can also call another constructor explicitly using the keywords  this() or  super(). The this() keyword calls another overloaded constructor  in the same class; the super() keyword calls a non-default constructor in a superclass. Implicit Constructor Chaining Constructor chaining occurs through the use of inheritance. A subclass constructor methods first task is to call its superclass constructor method. This ensures that the creation of the subclass object starts with the initialization of the classes above it in the inheritance chain. There could be any number of classes in an inheritance chain. Every constructor method calls up the chain until the class at the top has been reached and initialized. Then each subsequent class below is initialized as the chain winds back down to the original subclass. This process is called constructor chaining. Note that: This implicit call to the superclass is the same as if the subclass had included the super() keyword, i.e. super() is implicit here.If a no-args constructor is not included in the class, Java creates one behind the scenes and invokes it. This means that if your only constructor takes an argument, you must explicitly use a this() or super() keyword to invoke it (see below). Consider this superclass Animal extended by Mammal: class Animal {// constructorAnimal(){   System.out.println(Were in class Animals constructor.);}} class Mammal extends Animal {//constructorMammal(){   System.out.println(Were in class Mammal s constructor.);}} Now, lets instantiate the class Mammal: public class ChainingConstructors {   /*** param args*/public static void main(String[] args) {Mammal m new Mammal();}} When the above program runs, Java implicitly triggers a call to the superclass Animal constructor, then to the class constructor. The output, therefore, will be: Were in class Animals constructorWere in class Mammals constructor Explicit Constructor Chaining using this() or super() Explicit use of the this() or super() keywords allows you to call a non-default constructor. To call a non-args default constructor or an overloaded constructor from within the same class, use the  this()  keyword.  To call a non-default superclass constructor from a subclass, use the super() keyword. For instance, if the superclass has multiple constructors, a subclass may always want to call a specific constructor, rather than the default. Note that the call to another constructor must be the first statement in the constructor or Java will throw a compilation error. Consider the code below in which a new subclass, Carnivore, inherits from Mammal class which inherits from the Animal class, and each class now has a constructor that takes an argument. Heres the superclass Animal:   public class Animalprivate String name;public Animal(String name)  // constructor with an argument{this.name name;System.out.println(Im executed first.);}}Note that the constructor now takes a name of type String as a parameter and that the body of the class calls this() on the constructor. Without the explicit use of this.name, Java would create a default, no-args constructor and invoke that, instead. Heres the subclass Mammal: public class Mammal extends Animal {public Mammal(String name){super(name);System.out.println(Im executed second);}} Its constructor also takes an argument, and it uses super(name) to invoke a specific constructor in its superclass. Heres another subclass Carnivore. This inherits from Mammal:   public class Carnivore extends Mammal{public Carnivore(String name){super(name);System.out.println(Im executed last);}} When run, these three code blocks would print: Im executed first.Im executed second.Im executed last. To recap: When an instance of the Carnivore class is created, the first action of its constructor method is to call the Mammal constructor method. Likewise, the first action of the Mammal constructor method is to call the Animal constructor method. A chain of constructor method calls ensure that the instance of the Carnivore object has properly initialized all the classes in its inheritance chain.