Académique Documents
Professionnel Documents
Culture Documents
Course Instructor : Lect. Balraj Kumar____________ Course Tutor (if applicable) : ____________
Declaration:
I declare that this assignment is my individual work. I have not copied from any other student’s work
or from any other source except where due acknowledgment is made explicitly in the text, nor has any
part been written for me by another person.
Evaluator’s comments:
_____________________________________________________________________
PART A
Q:1 Define abstraction, encapsulation, modularity and hierarchy in your own terms.
Ans: Abstraction: Abstraction refers to the act of representing the essential features of a
program or system without including the basic details related to that program. In other
words in abstraction only the function the program or system performs is highlighted ,
what and how it happens in the background is hidden.
E.g. consider the case of a car or a software performing the addition of two
numbers .People only drive the car without considering what goes under the body of
the car to move. Similarly user enters two numbers without thinking what happens
behind the interface in adding those two numbers. Thus abstraction hides the basic
details in performing a particular function.
Q:2 Sketch the object-oriented design or the Card game Black-Jack. What are the
key objects? What are the properties and behaviours of these objects? How does
the object interact?
Ans:
Ans:
PART B
Q:4 In an object oriented inheritance hierarchy, the objects at each level are more
specialized than the objects at the higher levels. Give three real world examples
of a hierarchy with this property.
Ans: Examples of object oriented inheritance hierarchy in which the object at each level are
more specialized than other are:
1) Maruti 800 is the part of the classification car, which in turn is part of class
ground transport, which is under the larger class transport.
2) LIM is the part of the classification LPU, which in turn is part of class University,
which is under the broader and larger class Education.
3) Sea is the part of the classification Earth, which in turn is the part of Planet class,
which comes under the larger class Universe.
Ans: System.out.print() method prints the items or elements as output in a single line
whereas System.out.println() prints the output in the next line. Println() works as ‘\n’
used in C ,C++. E.g. If the numbers from 1 to 5 are to be printed then using
System.out.print() method all five numbers will be printed in a single line like 12345
whereas in case of System.out.println() all five numbers would appear in separate
lines like 1
2
3...
Class constant
Q:6 Write a code segment that defines a Scanner variable stdin that is associated with
System.in. The code segment should than define to int variables a and b, such
that they are initialized with the next two input values from the standard input
stream.
class add
int a,b,c;
a=stdin.nextInt();
b= stdin.nextInt();
c=a+b;
Q:7 Separately identify the keywords, variables, classes, methods and parameters in
the following definition:
import java.util.*;
public class test
{
public static void main(String[] args)
{
Scanner stdin = new Scanner(System.in);
System.out.print(“Number:”);
double n = stdin.nextDouble();
System.out.println(n + “ * “ + n + “ = “ + n * n);
}
}
Variables: stdin, n