Professional Documents
Culture Documents
Question 5: Objects that share the same attributes and behaviour are grouped
together into a/an ______________.
1. Interface 3. Alias
2. Instance 4. Class ✓
Explanation
A class is a template or blueprint for multiple objects with similar features and
maybe regarded as a specification for creating similar objects.
Question 8: ______________. is the feature by means of which one class acquires the
properties of another class.
1. Abstraction 3. Encapsulation
2. Inheritance ✓ 4. Polymorphism
Explanation
This is the definition of Inheritance.
Assignment Questions
1. What are programming languages? Describe the various generations of
programming languages.
A Programming Language is a set of commands and syntax used to create a computer
program. The various generations of programming languages are:
High Level language needs a compiler or Low Level language might need a assembler
interpreter for translation to machine code. for translation to machine code.
Programs written in High Level language Programs written in Low Level language are
are easier to modify and debug. hard to modify and debug.
1. The size of the programs created using this approach may become larger than
the programs written using procedure-oriented programming approach.
2. Software developed using this approach requires a substantial amount of pre-
work and planning.
3. OOP code is difficult to understand if you do not have the corresponding class
documentation.
4. In certain scenarios, these programs can consume a large amount of memory.
9. Differentiate between the Owner's and the Vet's perspective in Figure 1.24
From the viewpoint of the dog's owner, the things that are essential for the dog are his
favorite food, the colour of his food bowl, his favorite game that he enjoys playing with
his owner, his preferred time for walk, etc.
From the viewpoint of the dog's vet (doctor for animals), the important things about
the dog are whether the dog's body functions are normal or not to ensure that the dog
is healthy. Like this, there can be two abstractions for the dog — one for the dog's
owner and the other for the dog's vet.
For example, consider the operation of addition. For two numbers, the operation will
generate a sum. If the operands are strings, then the operation would produce a third
string by concatenation.
11. Differentiate between the Car Mechanic's and Car Driver's perspective in Figure
1.25
From the viewpoint of the driver, a car is one single object. It can be operated using
gears, indicators, accelerator, brake, etc.
The driver doesn't need to know or
understand the internal mechanisms of
how these components actually work.
From the viewpoint of the mechanic, it
is important for him to understand how
the internal mechanisms like gears,
indicators, accelerator, brake, etc. actually
work so that they can identify and fix
issues with the cars. For a mechanic, each
car part is a single object.
16. Explain the difference between Inheritance and Encapsulation with suitable
examples.
Encapsulation is a mechanism that binds together code and the data it manipulates
whereas Inheritance is the mechanism by which a class acquires the properties and
methods of another class.
An ATM binding together the different denominations of currency notes and all the
operations required to withdraw cash is an example of Encapsulation.
Classifying Vehicles as Car, Bike, Bus, Truck, etc. is an example of Inheritance.
17. What are the differences between Procedural Programming and Object-oriented
Programming?
Procedural Programming Object-Oriented Programming
Data security is less as it contains lesser It is more secure as one of its primary
features to protect the data. features include data hiding.
Limited and difficult code reusability. Versatile and easy code reusability.
Code is difficult to modify, extend and Code is easy to modify, extend and
maintain. maintain.
Assignment Questions
Question 1: Write a short note on types of Java programs.
There are two types of Java programs — Java Stand-Alone Applications and Java
Applets.
Java Stand-Alone Applications
A stand-alone Java application refers to a Java program that can run
independently on a computer. Acrobat Reader is an excellent example of this
type of application. In Java, every stand-alone application begins its execution
with the main() method. Java stand-alone applications can be classified into two
types:
a. Console based applications
b. Graphical User Interface based applications
Java Applets
Java applets are Java applications that run within a web browser. They are
mainly used for internet programming. The applet is capable of performing
many tasks on a web page, such as displaying graphics, playing sounds, and
accepting user input.
It converts the whole source program into It converts the source program into
the object program at once. the object program, one line at a time.
It contains the Java source code of the It contains the Bytecode of the
program. program.
Question 9: Describe the slogan, "Write once, run anywhere" in relation to Java.
Bytecode and JVM makes Java programs platform independent. This is one of the most
important and powerful features of Java. The Bytecode of a Java program can be run
on any platform that has a corresponding JVM installed on it. No modifications to this
Bytecode are required. Hence, it is said that Java provides "Write once, run anywhere"
capabilities.
The compiler processes the complete source program at once and if there are
compilation errors, they are all reported together at once.
(b) An interpreter
An interpreter is a program that reads a source program line by line, converts each line
into its equivalent machine code and executes it. As it reads the program line by line so
the errors are reported one by one.
JDK or Java Development Kit is the set of BlueJ is an IDE or Integrated Development
tools required to compile and run Java Environment for developing Java
programs programs.
static — When we declare a method inside a class as static, we can call it without
creating the object of that class. We need to make the main method static because Java
Virtual Machine (JVM) will call it to start the program even before any objects of the
class are created.
void — The void keyword tells the compiler that the main method will not
return any value.