Saturday, March 21, 2020

binge drinking Essays (433 words) - Drinking Culture, Alcohol Abuse

A driver's license for your teenager is a milestone and one of the biggest events in their young lives. The independence it gives them is wonderful, but can be quite frightening to a parent and can cause friction among the ranks. Teaching your teen to drive safely is a big undertaking and should not be taken lightly. Your teen?s life and the other driver?s lives may depend on how well you get your teen ready for this responsibility. Your child will have to handle a lot of instructions and rules of the road. While learning these new skills he will be stressed, yet he may try to appear cool under pressure. While some kids are confident and can?t wait to get started, others are anxious and may have to be nudged a little. Either way, arguments may ensue so plan your strategy accordingly. Obviously, make sure that the vehicle they will be using is in tip-top condition regarding brakes, good tires, a well charged battery and an emergency kit on board. Establish rules ahead of time. If they will listen to you, there will be less yelling on both ends. Limit conversation strictly to the task at hand. Remember that you are their teacher, not their friend, allowing you to be more productive and clearer when establishing the rules. Aside from the basics of how to drive, such as how to steer, park, and how to use their mirrors, here are some iron-clad rules before they can be allowed on the road. Depending upon what your weather conditions are in your state should determine if you?re teen can drive in them. Even some adults have trouble driving in adverse conditions, so don?t let them drive until you feel they are capable of driving in the rain, snow and ice. Stress the importance of wearing a seat belt. It is not only safer, but it is also the law. You would think that warning your teen against driving and drinking would be a no brainer, but do it anyway. If they do get into a situation of this nature, make sure they know that they should still call you. You cannot stress this enough. No headphones, no texting, and no driving when they are tired. If there are passengers in the car, they must still concentrate on driving. If they see that they are running late from school or their job, they must immediately call. It is a good idea for them to have a cell phone. This also insures that there will be no excuses!

Thursday, March 5, 2020

Using the Keyword Final with Inheritance in Java

Using the Keyword Final with Inheritance in Java While one of Javas strengths is the concept of inheritance, in which one class can derive from another, sometimes its desirable to prevent inheritance by another class. To prevent inheritance, use the keyword final when creating the class. For example, if a class is likely to be used by other programmers, you may wish to prevent inheritance if any subclasses created could cause problems. A typical example is the String class. If we wanted to create a String subclass: public class MyString extends String{ï » ¿} We would be faced with this error: cannot inherit from final java.lang.String The designers of the String class realized that it was not a candidate for inheritance and have prevented it from being extended. Why Prevent Inheritance? The main reason to prevent inheritance is to make sure the way a class behaves is not corrupted by a subclass. Suppose we have a class Account and a subclass that extends it, OverdraftAccount. Class Account has a method getBalance(): public double getBalance(){ return this.balance; } At this point in our discussion, subclass OverdraftAccount has not overridden this method. (Note: For another discussion using this Account and OverdraftAccount classes, see how a subclass can be treated as a superclass). Lets create an instance each of the Account and OverdraftAccount classes: Account bobsAccount new Account(10); bobsAccount.depositMoney(50); OverdraftAccount jimsAccount new OverdraftAccount(15.05,500,0.05); jimsAccount.depositMoney(50); //create an array of Account objects //we can include jimsAccount because we //only want to treat it as an Account object Account[] accounts {bobsAccount, jimsAccount}; //for each account in the array, display the balance for (Account a:accounts) { System.out.printf(The balance is %.2f%n, a.getBalance()); } The output is: The balance is 60.00 The balance is 65.05 Everything appears to work as expected, here. But what if OverdraftAccount overrides the method getBalance()? There is nothing to prevent it from doing something like this: public class OverdraftAccount extends Account { private double overdraftLimit; private double overdraftFee; //the rest of the class definition is not included public double getBalance() { return 25.00; } } If the example code above is executed again, the output will be different because the getBalance() behavior in the OverdraftAccount class is called for jimsAccount: The output is: The balance is 60.00 The balance is 25.00 Unfortunately, the subclass OverdraftAccount will never provide the correct balance because we have corrupted the behavior of the Account class through inheritance. If you design a class to be used by other programmers, always consider the implications of any potential subclasses. This is the reason the String class cannot be extended. Its extremely important that programmers know that when they create a String object, its always going to behave like a String. How to Prevent Inheritance To stop a class from being extended, the class declaration must explicitly say it cannot be inherited. This is achieved by using the final keyword: public final class Account { } This means that the Account class cannot be a superclass, and the OverdraftAccount class can no longer be its subclass. Sometimes, you may wish to limit only certain behaviors of a superclass to avoid corruption by a subclass. For example, OverdraftAccount still could be a subclass of Account, but it should be prevented from overriding the getBalance() method. In this case use, the final keyword in the method declaration: public class Account { private double balance; //the rest of the class definition is not included public final double getBalance() { return this.balance; } } Notice how the final keyword is not used in the class definition. Subclasses of Account can be created, but they can no longer override the getBalance() method. Any code calling that method can be confident it will work as the original programmer intended.