#
Quiz 2: Inheritance & Polymorphism
Create a checked exception named
InvalidUsernameException. Then create aLoginclass;Loginhas ausernameString variable and apasswordString variable. Its constructor must throw your new Exception if the username contains (in any letter casing) the word "admin". Then create aMainclass: its main method creates aLoginand prints its username and password. Show the best-practice way of doing this. (6/12)I created a class named
Rectanglewith an instance variables forlengthandwidth. Show its default constructor; under what conditions is that constructor made by Java? Create aSquareclass that is a child ofRectangletoo. (2/12)Create a class
Drinkwith instance data for name (a String). Create a child classCocaColathat also has a boolean for whether it is "diet" or not.Drinkhas a method callddisplay()that prints its data.CocaColaoverrides it and prints its data. (4/12)