Java Programming OOPs
Questions 281 to 290
281.
|
What is the output of the following
code?
class
Arithmetic {
public static void main (string args[])
{
int x=17, y=5;
System.out.println(“x =” +x);
System.out.println(“y =” +y);
System.out.println(“x+y=” +(x+y));
System.out.println(“x-y=” +(x-y));
System.out.println(“x*y=” +(x*y));
System.out.println(“x/y=” +(x/y));
System.out.println(“x%y=” +(x%y));
}
}
|
||||||||||
282.
|
What is the output of the following
code?
class
SpecialArithmetic {
public static void main (string args[]) {
int
x=17,a,b;
a=x++;b=++x;
System.out.println(“x=” + x +“a=”
+a);
System.out.println(“x=” + x + “b=”
+b);
a=x--;b=--x;
System.out.println(“x=” + x + “a=”
+a);
System.out.println(“x=” + x + “b=”
+b);
}
}
|
||||||||||
283.
|
What is the output of the following
code?
class
Bitwise {
public static void main (string args[]) {
int
x=5, y=6;
System.out.println(“x&y=” +(x
&y));
System.out.println(“x|y=” +(x|y));
System.out.println(“x^y=” +(x^y));
}
}
|
||||||||||
284.
|
What is the output of the following
code?
class
Shift {
public static void main (string args[
]) {
int x=7;
System.out.println(“x>>>1=”
+(x>>>1));
}
}
|
||||||||||
285.
|
class
Relational{
public static void main (string
args[]) {
int x=7, y=11, z=11;
System.out.println(“y<=z =” +(y<=z));
}
}
|
||||||||||
286.
|
char
chars[] = { ‘a’, ‘b’, ‘c’, ‘d’, ‘e’, ‘f’};
String s = new String(chars, 2,
3);
System.out.println (s);
What is the output of the above code?
|
||||||||||
287.
|
String
Firstname[]= new String[5]
String
firstName [ ] = { “Kamal”, “Amal” , “Nimal
“Saman”,
“Sunil” } ;
What is value of firstName[5]?
|
||||||||||
288.
|
int twoDMatrix [ ][ ] = new int [4][6];
int twoDMatrix [ ][ ] = { {5,1,2,8,6,9}
{8,4,1,6,2,1}
{3,9,2,5,8,9}
{1,7,3,6,4,3}
};
What
is the output of the following statement twoDMatrix[0].length?
|
||||||||||
289.
|
Which
operator is used for concatenation in java?
|
||||||||||
290.
|
class
Point {
int x,y;
Point (int x, int y) {
this.x = x;
this.y = y;
}
public String toString() {
return “Point[“ +x+ “,”
+y+ “]”;
} }
class toStringDemo {
public static void main (String
args[]) {
Point p = new Point (10,20);
System.out.println(“p=“ +p);}
}
What is the output of the following code?
|
Answers
281.
|
Answer : (b)
Reason: B is the right choice
|
282.
|
Answer : (d)
Reason: According to the rule of increment operator the choice is D.
|
283.
|
Answer : (b)
Reason: According to the rule of bitwise operator the choice is B
|
284.
|
Answer : (a)
Reason: According to the rule of the Right Shift operator the following
expression is evaluated to 3
|
285.
|
Answer : (c)
Reason: According to the rule of the Relational operator precedence c is
the apt choice.
|
286.
|
Answer : (c)
Reason: String(chars,2,3) means starting at the position 2 extract 3
characters.here indexing start from o so first character is c and remaining
are d and e.
|
287.
|
Answer : (e)
Reason: As the array is out of bound
|
288.
|
Answer : (d)
Reason: The given matrix is of 4 rows and each row containing 6 elements.
|
289.
|
Answer : (e)
Reason: + operator is used for concatenation in java
|
290.
|
Answer : (a)
Reason: Shows a class which overrides toString to show the values of its instance
variables.
|
<< Prev 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
23 24 25 26 27 28 29 30 Next >>
csharp coding examples
ReplyDeletethank you.
ReplyDeletejava tutorial
java tutorial
Thanks for this question and answers its very helpful.
ReplyDeleteJava course in Pune