Computer
Computer
2. Name the characteristics of Object Oriented Programming that hides the complexity
and provides a simple interface.
a. Encapsulation b.
Polymorphism
c. Abstraction d. Inheritance
Section A
Answer the following questions:
12. Write one difference between primitive data type and composite data type.
Ans.
Fundamental data type Composite data type
These are inbuilt data type provided by the These are data types created by the user using
Java Language. fundamental or user defined data type or both.
The size of it is fixed. The size of different user-defined data type
depends upon the size of the individual
components of it.
These data types are available in all parts These data types are available only as specified
of a program within a class. by the access specifiers.
13. Give one example each of primitive data type and composite data type.
Ans. Primitive data type: int, short, boolean, char etc.
Composite data type: class, arrays, interface etc.
17. State the difference between a Boolean literal and a character literal.
Ans. A boolean literal consist of only two values i.e. true or false. A character literal on the
other hand is any character enclosed within single quotes.
21. Evaluate the value of n if the value of p=5 and q=19: int n = (q-p)>(p-q)?(q-p):(p-
q); Ans. n=14
22. What is meant by precedence of operators?
Ans. When several operations occur in an expression, each part is evaluated and resolved in a
predetermined order called operator precedence.
23. What is Operator Associativity?
Ans. Operator associativity of an operator is a property that determines how operators of the
same precedence are grouped in the absence of parentheses; i.e. in what order each
operator is evaluated when two operators of same precedence appear in an expression.
27. Write a statement in Java that will declare an object named si of the SimpleInterest
class.
Ans. SimpleInterest si = new SimpleInterest();
28. Rewrite the following program after removing the errors, underlining each correction:
class My Class
{
int a, b;
void initialize( )
{
a=5;
b=6;
}
void show ( )
{
System.out.println (a+ ‘’ ‘’ + b);
}
static void main( )
{
My Class ob = new My Class ( );
ob. initialize ( ); show ( ).
ob;
}
}
Ans. class MyClass
{
int a, b;
void initialize( )
{
a=5;
b=6;
}
void show ( )
{
System.out.println (a+ ‘’ ‘’ + b);
}
34. What is the value of y after evaluating the expression given below? y+=++y + y-- +
--y; when int y=8
Ans. y=33
35. Give the output of the following expression:
a+=a++ + ++a + --a + a--; when a=7. Ans. a=39
37. What are the values of x and y when the following statements are executed? int a =
63, b = 36; boolean x = (a < b ) ? true : false; int y= (a > b ) ? a : b;
Ans. x=false y=63
38. What will be the result stored in x after evaluating the following expression? int
x=4;
x += (x++) + (++x) + x; Ans. x=20
40. What is the result stored in x, after evaluating the following expression?
int x = 5; x = x++ * 2 + 3
* –x; Ans. x=-8
43. State the number of bytes occupied by char and int data types.
Ans. char = 2 bytes
int = 4 bytes
ii.
cha
r