Code.org learning
Learning from Unit 1 on Code.org
Code.org Unit 1
Code.org taught me a lot of useful things about object-orientated programming, specifically with the java language. It’s especially important to go over the creation and use of objects along with the inheritance of classes.
Objects
Objects are the main feature of java, and they represent instances of a class (a blueprint for these objects). Objects are unique in the way that they can have their own attributes and methods, allowing the programmer who makes the class to tailor their objects to certain specifications. By calling their methods (with the dot operator), a programmer can use objects to perform tasks.
Here’s an example of using an object to paint certain things in code.org: Note how the object is established with “PainterPlus myPainterPlus = new PainterPlus();” and how it accesses its methods such as myPainter.moveFast();
Inheritance
One cool feature about classes in java is that class can inherit certain properties and methods from other classes. Members of the child class are able to access the same attributes and methods of the parent class, in the same way for both. Through this, programmers can create a very general parent class as a blueprint for more specific classes detailing attributes and methods specific to that class, while keeping the essential attributes and methods of the original.
Here’s an example of a class, PainterPlus, inheriting from the class Painter in code.org: Note how the class declaration of PainterPlus includes the “extends” keyword in order to inherit from Painter.
Here’s an example of how PainterPlus can use methods from both classes in code.org: Note how .move() is a method of Painter, while .turnRight() is a method exclusive to PainterPlus.