- Name any two OOP principles.
- State the Java concept that is implemented through:
i)
A super class and a subclass.
ii)
The act of representing essential features
without including background details.
- Which OOP principle implements function overloading?
- Define encapsulation.
- What is inheritance and how is it useful in Java?
- What is a package? Give an example.
- Name two types of Java programs.
- Name the following:
i)
A package that is invoked by default.
ii)
A keyword, to use the classes defined in a
package.
- Define the term Byte Code.
- Name of the following:
i)
A keyword used to call a package in the program.
ii)
Any one reference data types.
- Name the types of error (syntax, runtime or logical error) in each case given below:
(i) Division by a
variable that contains a value of zero.
(ii) Multiplication
operator used when the operation should be division.
(iii) Missing
semicolon.
- What will be the output when the following code segments are executed?
String s =
"1001";
int x =
Integer.valueOf(s);
double y =
Double.valueOf(s);
System.out.println("x="
+x);
System.out.println("y="
+y);
13. Give
the output of the following code:
String A=
"26", B= "100";
String D=A+B+
"200";
int x=
Integer.parseInt(A);
int
y=Integer.parseInt(B);
int d=x+y;
System.out.println("Result
1="+D);
System.out.println("Result
2="+d);
14. Mention
two different styles of expressing a comment in a program.
- Differentiate between operator and expression.
- If m=5 and n=2 output the values of m and n after execution in (i) and (ii) :-
i) m -= n;
ii) n = m + m/n
- What is a compound statement? Give an example.
- What will be the output of the following if x=5 initially?
i) 5 * ++x
ii) 5 * x++
19. What
is the output of the following?
char c = 'A';
short m = 26;
int n = c+m;
System.out.println(n);
20. Define
a variable.
- State the two kinds of data types.
- Find the output of the following program segment, when:
i) val = 500 ii) val = 1600
int val, sum, n=550;
sum = n + val > 1750 ?
400 : 200;
System.out.println(sum);
- What will be the output for the following program segment?
int a=0, b=30,
c=40;
a = --b + c++ + b;
System.out.println("a="
+ a);
24. Assign
the value of pi (3.142) to a variable of requisite data type.
- Explain the term type casting.
- State the difference between = and ==.
- Write an equivalent Java syntax for the following expression: a = 0.05 − 2y3 / x − y
- Rewrite the following using ternary operator:
if(income <
10000)
tax = 0;
else
tax = 12;
29. Write
a statement for each of the following:
1. Store a number
275 as a String
2. Convert the String
to a numeric value
3. Add it to the
existing total of 1000 to update the field
- What is the output of the following?
i)
System.out.println ("four :" + 4 + 2);
ii)
System.out.println ("four :" + (2+2));
- Evaluate the following expressions, if the values of the variables are a = 2, b=3 and c=9
i) a − (b++) * (−
−c)
ii) a * (++b) % c
32. Give
the output of the following expressions:
i) If x = -9.99,
calculate Math.abs(x);
ii) If x = 9.0,
calculate Math.sqrt(x);
- State the difference between a boolean literal and a character literal.
- What is the use and syntax of a ternary operator?
35. What
will be the output of the following code?
char x = 'A' ; int
m;
m=(x=='a') ? 'A' :
‘a’;
System.out.println("m="+m);
36. What
will the following functions return when executed?
(j) Math.max(-17,
-19)
(ii) Math.ceil(7.8)
- What will be the result stored in x after evaluating the following expression?
int x=4;
x += (x++) + (++x)
+ x;
- Give the output of the following program segment:
double x = 2.9, y =
2.5;
System.out.println(Math.min(Math.floor(x),
y));
System.out.println(Math.max(Math.ceil(x),
y));
- What is meant by precedence of operators?
- What are the types of casting shown by the following examples?
i) double x =15.2;
int y =(int) x;
ii) int x =12;
long y = x;
- Write a Java expression for ut + ½ ft2
- What is the data type that the following library functions return?
i)
isWhitespace(char ch)
ii) Math.random()
- Which of the following are valid comments?
(i) /* comment */
(ii) /*comment
(iii) //comment
(iv) */ comment */
- Name the primitive data type in Java that is:
(i) a 64-bit
integer and is used when you need a range of values wider than those provided
by int.
(ii) a single
16-bit Unicode character whose default value is ‘\u0000'
- State one difference between floating point literals float and double.
- Operators with higher precedence are evaluated before operators with relatively lower precedence. Arrange the operators given below in order of higher precedence to lower precedence.(i) && (ii) % (iii) >= (iv) ++
- Identify the statements listed below as assignment, increment, method invocation or object creation statements.
(i)
System.out.println(“Java”);
(ii) costPrice =
457.50;
(iii) Car hybrid =
new Car();
(iv) petrolPrice++;
- Give the output
System.out.println("The King said \"Begin
at the beginning!\" to me.");
- What are the final values stored in variables x and y below?
double a = - 6.35;
double b = 14.74;
double x =
Math.abs(Math.ceil(a));
double y =
Math.rint(Math.max(a,b));
- Give output of the following method:
public static void
main(String[] args) {
int a = 5;
a++;
System.out.println(a);
a -= (a--) - (--a);
System.out.println(a);
51. Explain,
with the help of an example, the purpose of default in a switch statement.
- Differentiate between if and switch statements.
- Explain with an example, the if..else if construct.
- The following is a segment of a program.
x = 1; y = 1;
if(n > 0)
{
x = x + 1;
y = y - 1;
}
- What will be the value of x and y, if n assumes a value (i) 1 (ii) 0?
- Give the output of the following code segment when (i) opn = ‘b’ (ii) opn = ‘x’ (iii) opn = ‘a’.
switch(opn)
{
case 'a':
System.out.println("Platform
Independent");
break;
case 'b':
System.out.println("Object
Oriented");
case 'c':
System.out.println("Robust and
Secure");
break;
default:
System.out.println("Wrong
Input");
}
- Rewrite the following program segment using the if..else statement.
comm =(sale>15000)?sale*5/100:0;
- Give two differences between switch statement and if-else statement.
- Rewrite the following program segment using the if-else statements instead of the ternary operator.
- String grade = (mark >= 90) ? "A" : (mark >= 80) ? "B" : "C";
- 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 ;
- Evaluate the value of n if value of p=5,q=19
int n =
(q-p)>(p-q)?(q-p) : (p-q);
- Rewrite the following using ternary operator :
if(x%2 == 0)
System.out.print(“EVEN”);
else
System.out.print(“ODD”);
No comments:
Post a Comment