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  


5 comments :

  1. This is a good article & good site.Thank you for sharing this article. It is help us following categorize:
    healthcare, e commerce, programming, multi platform,inventory management, cloud-based solutions, it consulting, retail, manufacturing, CRM, technology means, digital supply chain management, Delivering high-quality service for your business applications,
    Solutions for all Industries,packaged applications,business applications, Web services,
    Business intelligence, Business Development, Software Development etc.


    Our address:
    2002 Timberloch Place, Suite 200
    The Woodlands, TX 77380
    281-364-1799

    prologic-corp

    ReplyDelete
  2. AWT stands for Abstract Window Toolkit
    Not windowing

    ReplyDelete
  3. Absolutely delighted to read this post.Thank u very much

    ReplyDelete
  4. I need articles on data mining if possible

    ReplyDelete