Back 

Object oriented questions and answers

Questions

Q1. What is bytecode and why is it used?
Q2. What is an applet?
Q3. Explain the terms ‘class’ and ‘object’ using examples.
Q4. Explain what is meant by ‘data encapsulation’.
Q5. What are ‘methods’?
Q6. What does a constructor method do?
Q7. What is meant by polymorphism?
Q8. What is meant by inheritance in an OO program?
Q9. What is meant by a ‘sub-class’ and a ‘super-class’?
Q10. What are the key characteristics of an OO language?

Answers

Q1. Bytecode is an intermediate code produced by some languages for a virtual machine (one that doesn’t exist). The bytecode can then be distributed to different computers, each with their own hardware and software configuration. It is then a relatively easy job for each machine to translate the bytecode into code that it can run on itself. This is why Java, for example, is so powerful for use on the Internet. When you write a Java program, you have no idea about the wide range of computer configurations it will run on but by distributing bytecode instead (which can then be translated by each computer), you can overcome this problem.
Q2. Small programs called applets are written by programmers and transmitted with html code across the Internet. If you have a browser that has a Java bytecode interpreter (most of the latest ones have!) and you have enabled your browser to accept Java applets, then they will run when downloaded. Suddenly, very boring html web pages can be turned into anything the programmer wants to turn them into! Not everyone likes the idea of downloading and running programs not guaranteed to be virus-free and which may compromise personal privacy. As a result, some people disable Java applets on their PC!
Q3. A class is a template for a real life entity or object. For example, you might have a class called Student. It is used to create actual, real ‘objects’ called Mary Smith and John Stanley, who each have their own data (like first name, surname, date of birth, contact number and so on).
Q4. Data encapsulation means that you can only get to the data in an object by using the methods provided. It stops the data in an object being accidently changed, which could lead to bugs.
Q5. A method is a program that works on the data in an object.
Q6. A constructor is a special method that is used to create a new, real object from a class.
Q7. Polymorphism is the term used to describe the fact that we can have more than one constructor in a class. Each constructor can be used to create a real object of that class but needs different data at the time it is used. The idea of polymorphism is useful because you have more flexibility when you create a new object, depending upon how much information you know at the time of creation.
Q8. Inheritance is where one class can inherit the data and methods that belong to another class.
Q9. A super-class is above a sub-class in a UML diagram. The sub-class inherits the data and methods from the super-class.
Q10. The key characteristics of an OO language are that they must contain objects that have methods and data, with the data only being accessible via the methods. The objects must be instantiated from a class, making use of polymorphism. The classes must be able to inherit the properties of other classes.

Back