Guide · Examples · Object-oriented programming
Object-Oriented Programming – Example Tasks (Java)
Tasks on object-oriented programming, arranged from the first classes with attributes, through constructors and encapsulation, to arrays of objects, inheritance, polymorphism and interfaces. Every task has a hint and a solution in Java.
Meant for students who have mastered the basics (branching, loops, arrays) and are learning Java – at school, in a club or on their own.
- Secondary school and advanced primary school students
- Java
- Tasks with solutions
Some lessons linked below are available only in Serbian for now. They are marked (SR).
1 First classes and objects
Attributes, objects created with new and the first methods. Start here.
2 Constructors and encapsulation
An object sets and protects its own data: the constructor, private attributes, getters and setters, toString().
3 More objects: an array and ArrayList
Objects in an array or a list: the best one, the average, searching, sorting and removing.
4 Inheritance, polymorphism and interfaces
Several classes with common properties: extends, super, @Override, abstract classes, interface and Comparable.
5 Check your knowledge and continue
When you solve the tasks, do the test, and go back to the lessons for the theory.
Test: classes and objects (SR)
Tasks for checking your knowledge.
Open lesson →Lesson: Classes and objects in Java
Theory – attributes, methods, constructors.
Open lesson →Lesson: Class inheritance
Theory – the superclass and the subclass.
Open lesson →Guide: The Java programming language
All Java lessons in order.
Open lesson →Suggested order
- Classes and objects – basic tasks (tasks 1–13) (SR)
- Additional examples: classes and objects
- Constructors, getters and setters (then tasks 14 and 15 from the first page) (SR)
- An array of objects and ArrayList (SR)
- Inheritance, polymorphism and interfaces (SR)
- Test (SR)
Useful external resources
- dev.java – Learn Java – the official Java tutorial
- Java Tutor – running a program step by step, showing objects in memory
- OnlineGDB – Java – running Java programs in the browser
