You are on page 1of 9

Explicit type conversion means forcefully

converting one data type to another.


e.g.
int x == 68;

8.

i<5'i++)'

,..

x == x++ * 2 + 3 *
x == 25
b) (i) Output :
m == 3

(a) Mention any two attributes

.....

. r n n n +n),
(il) char x='A'; int m;
m=(x='a')
? 'A' : 'a';
System.out.println("m="+m);
(a) x == 5

==

f.

(2008)
[2010J

-- x;

Ans. (a) Attributes of a class can be primitive type or


reference type. To complete the class, we need to
specify data members, constructor and member
functions.
(b) Token. Smallest unit that constitute a program in

any programming language are called tokens of


that language. Tokens of java language are
keywords, identifiers, operators, literals and
punctuation marks.

a) Why is a class called afactory of objects?


b) State the difference between a boolean literal
and a character literal.

Identifier. An identifier is a token. It is a user-given


name that identifies a variable, a method, an object
or a class. e.g., class student {
}.

c) Write one word answer for the following:


(I) A method

that converts a stri~g to a


primitive integer data type.
(iz) The default initial value of a boolean
variable data type.
d) Why is a class known as composite data type?
(2009)

a) A class describes the features and functions of the


objects that can be created from it. It can be used
to create any number of objects, so it is called a
factory of objects.
.) Boolean literals are true and false. A boolean literal
can be stored in a variable whose data type is
boolean.
A character literal is any character enclosed within
single quotes. It can be stored in a variable whose
data type is char.
Examples:
boolean x == true;

char

required for class

(d) What ISmherztance and how ISIt useful m Java?

n == 14

(ii) m

(i) parselnt method of wrapper class Integer.


(ii) false.

int n=15;
for(int i-I'

(c)

==

boolean literal
'a' ;
character literal

Here, student identifies a class. So it is an identifier.


(c) Instance variable: A variable which is associated

with the object of a class is called an instance


variable. It is also known as data member or
member variable. Its scope is the entire class in
which it is defined. The scope of these variables
can be further enhanced or restricted based on the
access specifiers-private, protected and public or
default.
Example:
class Student
{

int rollNumber;
String name;

Here, rollNumber and name are instance variables.


It is a characteristic of object oriented
programming language. It states that the state and
behaviour (i.e., member variables and the methods)
ofa class (called Base class or Super class) can be
inherietd by another class (called sub class or
derived class).

(d) Inheritance:

Class as the Basis of all Computation

@J

Use of Inheritance:

e.g.,

System.out.print(x);
If the type casting

The derived class inherits the


embers of the base class.

(a) a-

class A
{

(b) a

Ans.

10.
Ans.

The resulting value of a=2, b=4 and c=


(b) a*(++b)%c
Considering
c=9
(2008)

(a) Name two types of Java programs.


(b) Define Instance Variable. Give an example of the
same.
(c) Assign the value of pie (i.e. 3.142) to a variable
with requisite data type.
(2007)
Ans. (a) Stand alone application programs and applets are
the two types of programs in java.
(b) An instance variable is a member of the class which
has its value associated with the ojects ofthe class.
For example,
class student {
int roll;
String name;
Student( int a, String b) {
roll=a;
name=b;
}
}
In the above program segment, roll and name are
the instance variables which will have their own
values for different objects.
(c) double p=Math.PI ;
12. Explain the term type casting.
(2007)
Ans.
Type casting means changing one data type to another.
Explicit type casting can be performed as shown in
the example below;
int b=97;
char x=(char)b;
/* explicitly type casting integer
type of data to character */

Computer Applications '(X)

the original values a=2,b=3

The result of the given expression = 8


The resulting value of a=2, b=4 and c=
IS.

Write a statement
(I) Store a number

11.

b) % c

The result of the given expression = -2_

a + = a++ - ++b + a;
Resulting value of a = 6

14417~

* (++

a=2, b=3, c=9;


(a) a-(b++)*(--c)

class B extends A
{
}
Here, A is base class
and B is derived class.
If a = 5, b = 9, calculate the value of
a + = a++ - ++b + a
a = 5, b = 9;

is not done, the error rmes _


on com i

(iz) Convert

for each of the following:


275 as a String

the string

to a numeric

value

(UI) Add it to the existing total of 1000 to updat


total.
(2
Ans.

(i) String number="275";


(ii) int num=Integer.parselnt(number);
(iii)

total=num+ 1000;

16. (a) Explain the term object using an example.


(b) Define a variable.
(2
Ans.

(a) Object. An object is an instance of a clas . _


Nokia 3315 is an instance of class cellp
Maruti is an instance of the class car.
(b) Variable. A memory location that stores a
is identified by a variable name. This stored
may change during the execution of the pr ::
and thus the name varyable. A variable stor
value of the type with which it is declared.

17.
Ans.
18.

State the two kinds of data types.

(2

Primitive data types and reference data types are


types of data types available in java.
Write the corresponding
expressions
for
following mathematical
operations:
(a) a2 + b2
(b)

Z=X3+y3_

xy

[2

Ans.

(a)
(b)

double c = Math.pow(a,2)
double z = Math.pow(x,3)

+ Math.powib.c
+ Math.pow(y, 3
- (x * )

(I) 5* ++ x
(iz) 5*x ++
(b) What is the output

What will be the output for the following program


segment?
int a = 0, b = 30, c = 40;

(i) Encapsulation:
Binding and wrapping up of
methods and data members together in the
form of a class is called encapsulation.
(ii) Abstraction:
Hiding unnecessary details and
representing
essential
features is called
abstraction.
(iii) Inheritance:
Inheriting the data members and
methods of objects of one class by another
class is called inheritance.
(iv) Polymorphism:
Same function may behave
differently
on different
classes. This is
represented by function overloading.
(b) Ifm = 5 and n = 2 then
(i) m-=n=:>m=m-n

i.e.,m=5-2=3
= 3, n = 2 after evaluation.
= m + mln
= 5 + 5/2 = 5 + 2 = 7

So, m
(ii) n
_1.

(a) What will be the output


x = 5 initially?

of the following,

if

of the followin

comment in a program.
(b) Differentiate
between operator and expression.
[20051
Ans. (a) A comment can be expressed in a program by
following two styles:
(i) II: For single line comments.
e.g., II This is a remark.
(ii) 1* *1: For multiple line comments. As it has
a beginning mark and an ending mark.
e.g., 1* This comment can proceed in
different lines *1
(b) An operator is a symbol that performs a specific
operation on the operands. An operator can be
unary operator and binary operator depending
on number of operands it operates upon.
e.g., +, -, *, I, % are binary operators.
++, --, are unary operators.
An expression is formed by the combination of
operators with operands.
e.g., a + b/2 * c is an arithmetic expression.

CE [lUESTI[)NS
1. What is a program ?
A program is a set of instructions written in a sequential
way to perform a specific application or to solve a
numeric or non numeric problem.
What are the known types of programming
languages?
Explain them.
Machine language, Assembly language and High level
language are some known types of programming
languages.
In machine language, the programs are written in
binary codes which are called machine codes or binary
codes.
In assembly language, the programs are written using
small symbolic words called mnemonics.
In high level languages, the programs are written in a
language which is closer to user i. e. english, just
following some rules specific for the language. Basic,

_
Pascal, Fortran, C, C++, java are some examples of
HLL. Object oriented programming languages (C++
and Java) are the high level languages.
3. What are procedural
languages ?
Ans. Developing a program with a process centric approach
is called procedural programming. It concentrates on
the processes for which the software is being built. In
this, the functions are highly interdependent on each
other. Procedural approach refers to breaking up of
complex problem into smaller problems and then
solving each by using modules which act on data.
4. What are the drawbacks
of using procedural
languages?
Ans. Drawbacks of using procedural languages:
(i) The modules (parts of programs) in a procedural
language strongly depend on each other. So, a
module cannot be reused by other programs.

Class as the Basis of all Computation

1451

(b) Behaviour

(ii)

of an object is the action tha:

performs.
s, ~-,:~.~~<::::l'

in software. Rea wor cons\s 0 0 le


has a set of attributes and behaviours.
6. What are the advantages of object orientation of
the programming language?
Ans. Advantages of object orientation:
(i) OOP approach models the real world quite
accurately as the programs written in this
language are focused on the objects rather than
the procedure.
(U) In OOP, classes are built up which can be used in

~~~~~~~~\.\.,~~,,\.te.\\.~~ce.s

reusabilitv,

-p~~,.-.

...~.....
-. ---:~.\::~::~.:-:~--;-'":!"'""::"'-~~~~~~~<.;~:>

~
r.... cl.~:s:s ..
raps

up

the

au.ribules

#.r/L'"e rhe

u.///;r-C/TCCS

o~r~pec.n

.p~:':':1;:r-;J

progrRmming Rnd Object oriented progrgmmlng.


,
~l\s.

A.numeric or non numeric problem can be so\veo ~)'


writing a program.Trus requrres rrrpee\~'fu~"-,,,>~~
program. The process takes place on the data and the
result is generated. The program can be written by
focusing on the process to be undertaken. i. e., "What
is the process ?'~.Another way to write a program is
by focusing on the fact that "What is the object that
will get effected by the program T",

7~

Computer Applications (X)

~"X,.,","a'\.., ~"bc

T< ...'o

0'1:

........
o\;. '-ne~e$

an example for each!

00

{c) !.~~\t~_~~~.t~

~~

__-....xc ~~"'----"'' ' ' ' -' ~

Kd'I{//'C.J:

The first type of program that focuses on process is


called procedural programming. This seems to be an
easier and direct method of solving the problem but
the software produced is inflexible to change when
the requirements demand the change.
The OOP organizes the program much closer to the
objects that get effected by the program that is being
constructed. So, first there is a need to identify the
objects from the application domain and then the
procedures are set for them. This is a better approach
when the requirements change.
8. Define. (0) Attribute (b) Behaviour (c) Method.
Ans. (a) An attribute is a characteristic of an object. In
programming terms, a data member is the attribute.

'-3.

~~

~:<"~'"~~~;~'~'~"".!!_~"'_!h~~~T~\)U~~ ~~d ~et~o'!i::(i


7:

How \5 encap u a on mp
Encapsulation refers to binding and wrappiru
the methods and the data. In java, it is implei
by the use of a class. Its significance lie!
abstraction feature of hiding the non es
implementation details. Inspite of hiding infon
the user can easily access the code and data cc
A class binds together the methods (called r
functions) and data (or attributes called memb
common to the objects that belong to it.
12. List all characteristics of an object.
~~.~,,,\.~~~\\.\,\, C\..assi..f\.cati.on, Inheritance

an.

'--'-~/~~';=:~_~L~.,.G",~~."....~~'-c~~~~

1f'J/

U1c t/WU/ff

'n\Q'
~
(7/

--

Eo

- ---

$~JffV'C$/~

c\xc~it of a television is bidden and on\'j


essentia\ components \\Ketne po'WeT,?\l~
~~~~"'-

~~~~~,,-~~~,,-~~

channel changer keys are available for us tc


Humans can easily manage the complexit
the systems through abstraction.
(b) Binding and wrapping up the methods ar
data (on which the method is applied) togel
called encapsulation. It keeps them safe
being misused or mishandled.
A
encapsulates state (features) and beha
(functions) of object.
(c) Inheritance is the process by which an I
acquires the properties of another object
Alsatian is a part ofthe classification dog,
itselfis a part of mammal class and this me
class is under the class animal. Here, AI
inherits the characteristics of dog, dog ir
the characteristics of mammal and rna
inherits the characteristics of animal clas
(d) It means that the same operationlfunctio
behave differently on different classes, e.
operation move behaves differently when a
to a Microsoft Window than when applie
chess game.

Is it possible that an object has more than one


abstractions? Explain with examples.

1!!!II __

the required inputs, process them and then shows the


desired result if the program is error free. And if the
~Yes, it is possible for an ob '~e~c~t
t~o~h~a~v~e~m~ogr~e~t~h~an~o~n~e~~~~~~!::!!::!!~~:::~::=======

==iiiiiiiiiii

an one c asses. rrru ar y, an


account holder can have the personal details in one
class say-AccHolder and the details of the account in
another class say-AccBalance.
- What is Java?
Java-A high level language: Java was envisaged
by James Gosling, Patrick Naughton, Chris Warth,
Ed Frank and Mike Sheridan at Sun Microsystems in
1991. It was originally named Oak. A need for
platform independent language (a language which isn't
effected by the architecture of the system and can be
used in any electronic device like T.V., ovens, etc.)
motivated the software engineers to develop it. Hence,
programs built in this language could also be used
for internet programming.
Java-A purely object oriented language : The
programs written in this language, are closer to the
objects that are effected by the program. Injava, even a
simple program to display a message needs a class to
be defined in which the methods are written.
Java-A case sensitive language: Java understands
the lowercase letters (a,b,c, etc.) and uppercase letters
(e.g., A, B, etc.) distinctly. So, sum, SUM and sUm
are identified differently in java.
Briefly state the evolution of java.
1991. The concept of java was envisaged by James
Gosling, Patrick Naughton, Chris warth, ed Frank and
Mike Sheridan at Sun Microsystems, Inc.
1994. The first working version "Oak" was developed,'
1995. Oak was renamed as "Java" and introduced
publicly.
1996. JOK 1.0 was distributed.
1997. 10K l.l version was introduced.
1998. 10K 1.2 commenced in the market.
2000. 10K 1.3 was released.
2002. 10K 1.4 was released.
2004. 10K 1.5 was released.
2006. 10K 1.6 was released.
- Define and then differentiate an interpreter from
compiler.
11 high level languages need to be converted to
achine codes known as binary codes so that the
achine (Computer) understands the program, takes

is much easier but the program takes longer time


to execute fully.
(ii) All the instructions can be converted to machine
language, all at once. All the errors are generated
and listed together. This is performed by a
software called Compiler. This process is much
faster than using an interpreter but beginners find
it difficult to mend all errors together in a
program.
18. How does Java compile its programs?
Ans. The java program (java is a high level language and
the program written in HLL is also called source code)
is compiled and converted to an intermediate level
language called Bytecode. This code is same
irrespective of the machine on which the program is
run. It means that Bytecode is machine independent.
This makes a java program highly portable as its
Bytecode can be easily transported from one system
to other without worrying about the system
architecture. When this bytecode is to be run on any
other system, what is only needed is an interpreter
called Java virtual Machine, which translates the
bytecode to the specific machine code. Thus, the java
program uses both the compiler as well as interpreter.
19. How is java compilation different from ordinary
compilation ?
Ans. Languages other than java only need either a compiler
or an interpreter to translate the high level language
to machine codes. The source code may be translated
line by line to generate one error at a time or it may
be compiled to generate all errors together. Which
ever way it might use to compile the programs, it
produces the code which is specific for the machine
it is being operated upon.
Java compilation is explained in the previous answer.
20. Define the term Bytecode.
Ans. Java code gets compiled to byte code. It is platform
independent code.
21. What is the need of JVM ?
Ans. Java Virtual Machine compiles the java program and
converts it to bytecode. This bytecode can be
translated to machine specific code.

Class as the Basis of all Computation

22. What features of java have made it so popular that


a need has been felt to introduce it at beginners

Ans.

A keyword is a reserved word of a language


has a special meaning when used in programs.
33. How many keywords of java are known till t

evel?

ypes 0
(i) Stand alone applications
- programs that are
written and compiled on the same machine.
(ii) Applets - programs executed on web browser.
(iii) Servlets - server side programs.
24. Why is java called Internet language?
Ans. Java programs are translated to java bytecode. Since
bytecode is not effected by the machine environment,
it is easier to run these programs on a wide range of
machines. Only a java interpreter JVM is required to
be implemented on the machines. JVM along with the
java Application Interface libraries acts as a platform
for the java programs to run on the machine. All JVM's
interpret the same bytecode. This makes the program
easier to be transported to variety of machines thus
making it portable. The world wide web on the internet
demands portable programs as of java, to be distributed
on the internet.
The second reason for its popularity as an internet
language is that it concentrates
on the real world
objects.
25. Expand

the abbreviation

Write the rules for nammg I en I ers.


An identifier must not begin with a digit. Th
letter can be an alphabet, underscore( _ ).
Spaces
and other special
character
+,_, * ,1,_, '@,#,!"&< > ? } { [] I etc are not all
$ sign and _ are accepted.
An identifier must not be a keyword.
Uppercase letters and lowercase letters are di
treated in java, i. e., Sum, SUM and s
different identifiers.
37. What is the difference between convention
rules?
If the rules are violated, errors are generated'
program. But conventions violation doesn't I
errors. Conventions are followed and practiced
professional level and if followed they give th
form and quality of a program. It gives clari
meaning to the words used.
38. Identify the following as valid variable nam

Ans.

reason if unvalid
(0) _123

IDE. Name two IDE;s

commonly known.
Ans. IDE stands for Integrated Development Environment.
Eclipse and BlueJ are two commonly used IDE's.
26. Name the IDE used to run java programs.
Ans. For java BlueJ environment is used as an IDE.

(c) var.l
(e)
(g)
(I)
Ans. (a)

L~~

7~

wid Computer Applications (X)

aJlowed.

(h) ace no is valid.


(i) accountno is valid but does not follow con
It should be accountNo.
(j) depositamount is not following conventio

30. What is a token?

of java ?

* not

(g) Invalid, space is not allowed.

Ans.

refer to in context

(d) TS

C23
(f) C*23
C 23
(h) acc_no
accountno
(J) depositamount
_123 is valid as it begins with _ (undersco

(d) Valid
(e) Valid
(j) Invalid, special character

Ans. Unicode.
29. What is the character set of the language Java?
Ans. A set of characters which is valid for a specific
language. Java uses UNICODE character set.

java.
32. What does the token 'Keyword'

(b) break

(b) Invalid, as break is a keyword.


(c) Invalid, dot (.) is not allowed.

27. What is a character?


Ans. An alphabet,
a digit, a space and other special
characters that have a mark are called characters.
28. What is the name given to character set of java ?

A token is the smallest unit which depicts the smallest


part of a high level language program.
31. List the names of different tokens of java.
Ans. keywords, identifiers,
punctuators,
operators and
literals are the tokens of the languages C, C++ and

otherwise it is valid.
39. Which of the following are valid integer lite
(0) - 5.0
(c) 4 x 10-3
Ans.

(b) 21

(b) 21
(d) -16E+03.

~O. Which

of the following

are

invalid

Ans. (b) 03 and (d) 0 I


52. Which of the following

identifier

names?

are valid

hexadecimal

What is a literal?
A constant value is called a literal.
2. What are the different

;t

e
L

ly
re
Id
he
to
he
est
nd
de

tion,

lis?

types of literals?

Types of literals are: integer literal, character literal,


floating literal, string literal and boolean literal.
3. What are the different types of integer literals?
Octal, Decimal and hexadecimal literals are the types
of integer literals.
How can different
types of integer
differentiated
in their identification?

literals

be

An octal integer is always preceeded


by 0, a
hexadecimal no. is always preceeded by \Ox and a
decimal number is not preceeded
by any such
characters.
-:. What are the two forms of floating literal?
Two forms of floating literals are standard floating
literal and scientific floating literal.
What is the equivalent scientific floating notation
of the following:
(a) 4.19 x 106
(b) 21.4652
(c) 0.461 x 10-2
(d) 13 X 1012
(a)4.19E+06
(b) 2.14652E+Ol
(c) 4.6IE-03
(d) 13E+12
- What are boolean literals?
- Boolean literals are true and false.
What are character literals?
Single character enclosed in single quote is called a
character literal e.g., 'a'.
What are string literals?
et of characters enclosed in double quotes is called a
string literal e.g., "abc".
Identify the following literals as character/string
literals:
(a) \0
(b) At
(c) Karam Arora!#
(d)\01
(e) \t
(f) \NASCII
(g) 0
a) Character
(b) String
c) String
(d) String
e) Character
(j) String
~) Character
, hich of the following are/is an octal integer
literal?
a) 09
(b) 03
c) 17
(d) 01

55.
Ans.

56.
Ans.
57.
Ans.

58.
Ans.
59.

Ans.

60.

Ans.

61.
Ans.
62.
Ans.

at ar varia
e ?
Memory location that stores a literal is called a
variable. It is identified by a variable name. Its value
can change in the program.
What do you mean by 'data type' of a variable?
Data type refers to the type of value to be stored in a
variable or the type of val ue to be used for calculations
and other manipulations in the expressions.
What are the different set of data types available
in java ?
Primitive data types and reference data types are two
types of data types available in java.
What are the different primitive data types?
int, byte, short, long, float, double, char, boolean are
primitive types.
List various reference data types of java.
Arrays and class are the reference data types and object
is a variable of data type class.
Write the size of the following integer data types
both in terms of bytes and bits:
(a) int
(b) short
(c) long
(d) byte
(a) int
4 Bytes
4 x 8 bits = 32 bits
(b) short
2 Bytes
16 bits
(c) long
8 Bytes
64 bits
(d) byte
i Byte
8 bits
Write the range of acceptable values of these data
types:
(a) int
(b) short
(c) long
(d) byte
(a) Range of values for int = _231 to 231 - I
(b) Range of values for short = _215 to 215 - I
= -32768 to 32767
(c) Range of values for long type = _263 to 263 - I
(d) Range of values for byte type = _27 to 27 - I
= -128 to 127
Write the size of (0) float (b) double in bytes and
bits.
(a) float = 4 Bytes = 32 bits
(b) double = 8 Bytes = 64 bits
Write the range of acceptable values of:
(a) float
(b) double
(a) -3.4 x 1038 to 3.4 x 1038
(b) -\. 7 x 10-308to I. 7 x I0308

63. How many bits are reserved for char data type '!
Ans. For character type values, it reserves 16 bits.

Class as the Basis of all Computation

L491
,/

64. Name the character


acters from all

Comments can also be written by beginning


and then ending of co~ment is indica~e.d by * .

set of java that includes


ossible human languages.

o to

II This statement initializes the age as 9

What is the range of values in Extended

set?

128 to 255
How many bits are reserved for boolean type?
8 bits are reserved but used only I bit.
How many bits does it use to store the boolean
value?
It uses only one bit.
What does a bit stand for?
Bit is an abbreviation for Binary Digit.
What are the two binary digits?
and I.
Ans.
What
boolean value does bits 1 and 0 represent
72.
respectively ?
Ans. I represents true and 0 represents false.
73. How many values can a variable store at a time?
Ans. A variable can store only one value at a time.
List the known
74. What are escape sequences?
sequences with their functions?
if preceeded by a backslash(\),
Ans. Some characters,
change their meaning and perform a specific function.

Ans.
70.
Ans.
71.

Escape sequences
\a audible bell
\b backspace
\n new line
\fform feed

are:
\v vertical tab
\t horizontal tab
\' quote
\" double quotes

\r carriage return
75. Write a java statement

to compute

discount

by

by MP.
Ans. double x=(double) totaIIlOO*MP;
76. Write a java statement to assign character X to a
variable val.
Ans. char val='X';
77. Write java statement to print the value of variable
val.
Ans. System.out.println(val);
78. What are comments/remarks
?
Ans. Comments or remarks refer to the statements which
are ignored by the java compiler and hence do not
effect the processing
and the output. These are
generally used to state the purpose of the instructions
used in the program.
79. How can you give comments in a java program.
Ans. In java the comments can be inserted by putting II
The entire line after /1 is treated as comment.

?~

Computer Applications eX)

Ans, +, -, *, I, %
82. Is a++; equivalent to ++aj ?
Ans, The two statements if written independently'
the value of a by I.
e.g., int a=IO;
a++;
System.out.println(a);
The above statements will result II as the a

a.
e.g., int a=IO;
++a;
System.out.println(a);
The above statements will also return II as

a.

following method :
Divide the variable total by 100. Multiply the result

(b) int num=25;


1* This statement is a remark.*1
float age = 14.0;
1* This statement initializes age as 14 *
80. What are binary operators?
Ans. The operators that takes two operands to opera
are called binary operators.
81. Write the arithmetic
binary operators.

But they behave differently if ++a or a++ are


associated with other operators,
e.g., int a=50, b;
b=a++;
System.out.println
(b+" "+a);
Here, assignment will be done first and then
a will be incremented so, b=50 and a=51 a
of execution.
83. What is the difference in Pre-increment, Post-i
and Pre-decrement, Post-decrement ?
Ans, Pre-increment
operator ++ is applied be
operand.
e.g.,
++x;
It increments the value of operand by I
performs any other operation associated with
e.g.,
int x=5;
System.out.println(++x);
Output:
6
Post-increment operator (++) is applied at ~
the operand as x++. It first performs the
operations and then increments the opera
by I.
e.g.,
int x = 2;
System.out.println(x++);

Output: 2 /
Pre-decrement (--) and Post-decrement works same as
Pre-increment and Post-increment respectively with a

System.out.println ("Result =" + x);


Ans. Result=25.
94. State the value stored in e.

executing statements b =a ++j.


b = -5, a =-4
What values will be stored in x and Y after
executing:
intx=10,yj

What value is now stored in e ?


Ans. 70.4
96. inta=b=Oj
What is the value stored in a and b ?
Ans. Error in the statement. Correct statement is :
int a=O, b=O;
97. Name the class modifier that makes the class visible
to other classes of same package.
Ans. public
98. Write the java expressions for the following
statements where x and yare predefined variables:

Y=++Xj
s. y= II,x= II

What values will be stored


executing:
int x= 10, Yj

in x and Y after

y=x--j

x=9,y=
10
What values will be stored in x and y respectively
after executing the following:
int x = -10,Yj
Y=--Xj
-II, -II

Consider the following statement of the program:


int a = 20j a + = 2j
What value will be stored in a now?
22
Consider the following statement:
int b = 5j b - = lOj
What value does variable b now stores?

of

-5
If a stores 45, b stores 2, e = a % b. What value" is
tored in e ?
I
i

of

lent
the

:he

_ Consider the statements:


int a = 50, b = 26, m = ++a
What is the resulting value in m ?
-I

_ The result returned


tatements is :
intx = S;
x. =5j

by the following

SECTION-B

java

(a) S = 5x

+ 2y

(e) S = ut

+ - at2

(b) S =
(d)f=-+-

3x2 + 2y
x-y
1

Ans. (a) int S=5*x+2*y;


(b) double S=(3*x*x+2*y)/(x-y); /*it is essential to
put parenthesis around the numerator and
denominator in this expression*/
(e) double S= u*t+ 1.0/2*a*t*t;
(d) double f=l.O/u + l.O/v;
99. Identify the errors in the followingjava statements
and correct them:
(a) long number
= 50,000
(b) boolean var
= 1j
(e) int num
= +10j
(d) int x/l0
= Yj
(e) short x + 5
= 15j
(f) char al
= "/0" j
(g) byte al
== 5 j
Ans. (a) correct statement: long number=50000;
(b) boolean var=true;
(e) int num+=IO;
(d) int x=y/l 0;
(e) shortx=15+5;
if) char al='\O';
(g) byte al=5;

LONG ANSWER TYPE QUESTIONS

US YEARS' (lUESTIDNS
id

iate
taiu

Prepare a list of attributes (data values), methods


and their description that you would expect the
objects of the following classes to handle:

_
(a) class Employee
(e) class BankCustomer

(b) class Student

Class as the Basis of all Computation

You might also like