WEBVTT 1 00:00:00.220 --> 00:00:03.005 In this demo I'm going to create and inspect 2 00:00:03.006 --> 00:00:05.100 an instance of the BonusItem class. 3 00:00:05.223 --> 00:00:08.114 BonusItem is a subclass of the Item class 4 00:00:08.115 --> 00:00:10.113 that was previously in the project 5 00:00:11.227 --> 00:00:13.226 so lets create an instance 6 00:00:14.009 --> 00:00:18.117 BonusItem has two constructor parameters, description 7 00:00:19.220 --> 00:00:21.227 and codeWord 8 00:00:22.004 --> 00:00:24.118 so I'll just put in values for those 9 00:00:25.001 --> 00:00:28.009 and the instance is created in the object bench. 10 00:00:30.003 --> 00:00:31.224 So lets inspect the object 11 00:00:31.229 --> 00:00:34.111 before I do so, lets just have a quick look at the 12 00:00:34.111 --> 00:00:36.118 code inside the BonusItem class 13 00:00:36.220 --> 00:00:40.227 and notice it declares only one field codeWord 14 00:00:41.228 --> 00:00:44.226 so now I inspect the object 15 00:00:45.001 --> 00:00:47.224 and you can see the BonusItem object has two fields 16 00:00:47.225 --> 00:00:50.008 description and codeWord. 17 00:00:50.117 --> 00:00:53.007 only one of these was declared inside 18 00:00:53.112 --> 00:00:55.224 the BonusItem class itself. 19 00:00:56.009 --> 00:00:59.006 Note that a BonusItem object combines fields 20 00:00:59.007 --> 00:01:01.223 that are declared in two different classes 21 00:01:02.111 --> 00:01:05.002 but the object itself is a single object. 22 00:01:09.222 --> 00:01:11.221 Let's look at the methods that we can call 23 00:01:11.222 --> 00:01:15.008 on this BonusItem object, if I right click on the object 24 00:01:15.115 --> 00:01:17.223 you can see the bonus method 25 00:01:17.224 --> 00:01:19.222 thats the only method that is defined 26 00:01:19.223 --> 00:01:21.113 in the BonusItem class 27 00:01:22.001 --> 00:01:25.004 I can call that and it produces some output 28 00:01:27.225 --> 00:01:30.119 but a BonusItem is a special type of item 29 00:01:30.220 --> 00:01:32.220 so it also should be able to do anything 30 00:01:32.222 --> 00:01:34.117 that an Item object can do 31 00:01:35.007 --> 00:01:38.004 and BlueJ lets us get at the methods 32 00:01:38.112 --> 00:01:40.113 that it inherits from an item 33 00:01:40.118 --> 00:01:43.004 with this menu option here then we can see 34 00:01:43.112 --> 00:01:46.116 all the methods that are part of the Item class. 35 00:01:46.229 --> 00:01:49.113 There is the use method that is defined an item 36 00:01:49.114 --> 00:01:52.221 I can call that on this BonusItem object 37 00:01:53.009 --> 00:01:56.111 and I get the output from that method. 38 00:01:59.004 --> 00:02:00.228 Note that all classes in Java 39 00:02:00.229 --> 00:02:03.118 are subclasses of a base class called Object 40 00:02:03.224 --> 00:02:06.115 so BonusItem is a subclass of Item 41 00:02:06.223 --> 00:02:09.112 which in turn is a subclass of Object. 42 00:02:10.114 --> 00:02:12.226 From the BonusItem object I can call 43 00:02:12.227 --> 00:02:16.113 the methods that are defined in the BonusItem class itself 44 00:02:16.228 --> 00:02:19.225 methods that are defined in the Item class 45 00:02:20.110 --> 00:02:23.117 and methods that are defined in the Object class. 46 00:02:24.005 --> 00:02:25.220 I'm not going to worry too much about what 47 00:02:25.221 --> 00:02:28.009 the Object class methods do for the moment though.