Showing posts with label Java. Show all posts
Showing posts with label Java. Show all posts

Java Programming Questions and Answers Set 30

Java Programming OOPs

Questions 291 to 300



291.
String s1 = “Hello”;
String s2 = “Hello”;
System.out.println(s1 + “equals” + s2 + “->” + s1.equals(s2));
What is the output of the following code?
(a)
Hello equals Hello -> 0
(b)
Hello equals Hello -> 1
(c)
Hello equals Hello -> false
(d)
Hello equals Hello -> true
(e)
Hello equals Hello -> hello.
292.
Given below is the syntax of the method declaration in java.
Syntax: modifier returnType MethodName (parameter List) {
            statement(s);
}
Which defines the Signature of the method?
(a)
modifier
(b)
modifier, returntype
(c)
return type, method name
(d)
returntype, methodname and parameter list
(e)
modifier, returntype, methodname and parameter list.
293.
What modifier is to be used If you wish to declare that you want  to no longer allow subclasses to override your variables or methods?
(a)
Finally
(b)
Abstract
(c)
Final
(d)
Synchronized
(e)
Volatile.
294.
Which access specifier is used for describing Applet Class?
(a)
Private
(b)
Public
(c)
Protected
(d)
Either (a) or (b)
(e)
Either (b) or (c).
295.
The following program takes any number of numeric arguments & returns the sum & the average of those arguments. When this program run, is it throws an error? Find which line number is to be modified to give the correct output?
Line 1)class SumAverage {
Line 2)public static void main(String args[]) {
Line 3)int sum = 0;
Line 4)for (int I = 0; i<args.length; i++) {
Line 5)Sum += args[i];
}
Line 6)System.out.println(“Sum is;” + sum);
Line 7)System.out.println(“Average is:” +
Line 8)(float) sum / args.length);
}
}
(a)
Line 3
(b)
Line 4
(c)
Line 5
(d)
Line 8
(e)
Line 2.
296.
Select the exception class from among the following which is  part of the java.lang package.
(a)
Inputstream exception
(b)
IOException
(c)
MalFormedURLException
(d)
RunTimeException
(e)
EOFException.
297.
Consider the following variable declarations.
int a, b; String str;
Assume that at some point of the program, the variables a and b contain the values 5 and 7.
Select from among the following the correct option which assign the variable str with the value “The sum of 5 + 7 = 12”?
(a)
str = “The sum of a + b = a + b”;
(b)
str = “The sum of  “ + a +” + “+ b +” =”  + a + b;
(c)
str = “The sum of  “+ a +” + “+ b +” =”  + (a + b);
(d)
str = “The sum of a + b =” + (a + b);
(e)
str = “The sum of a + b = (a + b)”;.
298.
Select from among the following character escape code which is not available in Java.
(a)
\t
(b)
\r
(c)
\a
(d)
\\
(e)
\v.
299.
Consider the following program written in Java.
class Selection{
  public static void main(String args[]){ int x=7; if(x==2); //? Note the semicolon
  System.out.println("Number seven");
  System.out.println("Not seven"); } }
What would the output of the program be?
(a)
Number seven
Not seven
(b)
Error
(c)
Not seven
(d)
Number seven
(e)
7.
300.
AWT stands for
(a)
Advanced windowing tool kit
(b)
Abstract Windowing Term Kit
(c)
Abstract Windowing Tool Kit
(d)
Applet Window Tool Kit
(e)
Asynchronous windowing tool kit.



Answers


291.
Answer : (d)
Reason:  If we use the equals method in String It will return true if the single parameter is made up of the same characters as the object you call equals on.
292.
Answer : (d)
Reason:  D is the right choice for method declaration.
293.
Answer : (c)
Reason:  Final modifier is to be used If you wish to declare that you want  to no longer allow subclasses to override your variables or methods?.
294.
Answer : (b)
Reason:  All applets must be declared public because the Applet class is a  public class.
295.
Answer : (c)
Reason:  SumAverage.java.6: Incompatible type for +=. Can’t convert
java.lang.String to int.
Sum += args[i];
You have to convert them from strings to integers using a class method for the Integer class called parseInt.
Sum += Integer.parseInt(args[i]);
296.
Answer : (d)
Reason:  Remaining all are contradictory to the given statement.
297.
Answer : (c)
Reason:  C is the right choice remaining all are not syntactically correct
298.
Answer : (c)
Reason:  \a is not the escape sequence character when compared to other.
299.
Answer : (a)
Reason:  A is the right choice .
300.
Answer : (c)
Reason:  AWT stands abstract Windowing Tool Kit.


<< 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  
Read More


Java Programming Questions and Answers Set 29

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));
   }
}
(a)
5, 17, 12, 85, 3, 2
(b)
17, 5, 22, 12, 85, 3, 2
(c)
17, 5, 20, 21, 85, 3, 2
(d)
2, 3, 85, 12, 22, 5, 17
(e)
17, 5, 12, 22, 85, 2, 3.
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);
          }
}
(a)
x=18 a=17
x=19 b=19
x=18 a=19
x=17 b=17
(b)
x=19 a=17
x=18 b=19
x=18 a=19
x=17 b=17
(c)
x=19 a=17
x=19 b=19
x=18 a=20
x=17 b=17
(d)
x=19 a=17
x=19 b=19
x=18 a=19
x=17 b=17
(e)
x=19 a=18
x=19 b=19
x=18 a=19
x=17 b=17.
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));
            }
}
(a)
x&y=5
x|y=7
x^y=3
(b)
x&y=4
x|y=7
x^y=3
(c)
x&y=6
x|y=7
x^y=3
(d)
x&y=4
x|y=8
x^y=3
(e)
x&y=4
x|y=8
x^y=4.
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));
       }
}
(a)
x>>>1=3
(b)
x>>>1=6
(c)
x>>>1=4
(d)
x>>>1=5
(e)
x>>>1=2.
285.
class Relational{
         public static void main (string args[]) {
               int x=7, y=11, z=11;
               System.out.println(“y<=z =” +(y<=z));
 }
}
(a)
y<=z = 0
(b)
y<=z = 1
(c)
y<=z = true
(d)
y<=z = false
(e)
y<z = true.
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?
(a)
abc
(b)
bcd
(c)
cde
(d)
deb
(e)
acd.
287.
String Firstname[]= new  String[5]
String firstName [ ] = { “Kamal”, “Amal” , “Nimal
                                                            “Saman”, “Sunil” } ;
What is value of firstName[5]?
(a)
Kamal
(b)
Amal
(c)
Saman
(d)
Sunil
(e)
Throws an exception.
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?
(a)
3
(b)
4
(c)
5
(d)
6
(e)
7.
289.
Which operator is used for concatenation in java?
(a)
-
(b)
Dot
(c)
*
(d)
%
(e)
+.
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?
(a)
p = Point[10,20]
(b)
p = Point[20,20]
(c)
p = Point[20,10]
(d)
p = Point[11,20]
(e)
p = Point[10,21].





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 >>
Read More