#
Quiz 2: Inheritance & Polymorphism
Create a checked exception named
InvalidUsernameException
. Then create aLogin
class;Login
has ausername
String variable and apassword
String variable. Its constructor must throw your new Exception if the username contains (in any letter casing) the word "admin". Then create aMain
class: its main method creates aLogin
and prints its username and password. Show the best-practice way of doing this. (6/12)I created a class named
Rectangle
with an instance variables forlength
andwidth
. Show its default constructor; under what conditions is that constructor made by Java? Create aSquare
class that is a child ofRectangle
too. (2/12)Create a class
Drink
with instance data for name (a String). Create a child classCocaCola
that also has a boolean for whether it is "diet" or not.Drink
has a method callddisplay()
that prints its data.CocaCola
overrides it and prints its data. (4/12)