The structure of Java code – revisited
We have already seen that each time we create a new Android project, we also create a new Java package as a kind of container for the code we write.
We have also learned about and played around with classes. We have imported and taken direct advantage of classes from the Android API such as Log and Toast. We have also used the AppCompatActivity class, but in a different manner to Log and Toast. You might remember the first line of code in all our projects so far, after the import statements, used the extends keyword:
public class MainActivity extends AppCompatActivity {
When we extend a class as opposed to just importing it, we are making it our own. In fact, if you take another look at the line of code, you can see that we are making a new class with a new name, MainActivity. but basing it on the AppCompatActivity class from the Android API.
Important note
The AppCompatActivity class is a slightly modified version of the...