Right Place For Right PersonTM 
Sponsored Ads
Buy This Website(This website is for Sale)
Home Tutorials Articles Forums Source Code Books Certifications Interviews Questions

Previous Home Next

Sun Java Certification Program

Fundamental classes

Questions 1 What is the output of the following:
StringBuffer sb1 = new StringBuffer("Amit");
StringBuffer sb2 = new StringBuffer("Amit");
String ss1 = "Amit";
System.out.println(sb1==sb2);
System.out.println(sb1.equals(sb2));
System.out.println(sb1.equals(ss1));
System.out.println("Poddar".substring(3));
a) false
false
false
dar
b) false
true
false
Poddar
c) Compiler Error
d) true
true
false
dar

Questions 2 Which of the following will output -4.0 ?
(a) System.out.println(Math.floor(-4.7));
(b) System.out.println(Math.round(-4.7));
(c) System.out.println(Math.ceil(-4.7));
(d) System.out.println(Math.min(-4.7));

Questions 3 What will be the result when you attempt to compile this program?
public class Rand {
public static void main(String argv[]){
int iRand;
iRand = Math.random();
System.out.println(iRand);
}
}
(a) Compile time error referring to a cast problem.
(b) A random number between 1 and 10.
(c) A random number between 0 and 1
(d) A compile time error about random being an unrecognised method.

Questions 4 What will be the result of compiling and running the given program?
Select one correct answer.
1 class Q2
2 {
3 public static void main(String arg[])
4 {
5 StringBuffer s[]={"A","B"};
6 System.out.println(s[0]+","+s[1]);
7 }
8 }
(a) Program compiles correctly and print A,B when executed.
(b) Compile time error.
(c) Run time error.

Questions 5 What will be the value of str after line no.7?
Enter your answer in the given field. Don't use any extra signs like ("")quotes or any string like "str=". For example, if your answer is the string "XYZ" you just write XYZ
1 class string
2 {
3 public static void main(String ds[])
4 {
5 String str="A";
6 str.concat("B");
7 str+="C";
8 }
9 }

Questions 6 What will be the result of compiling and running the given program?
Select one correct answer.
1 class strings
2 {
3 public static void main(String arg[])
4 {
5 if("String".indexOf("S",-10) ==0)
6 {
7 System.out.println("Equal");
8 }
9 else
10 {
11 System.out.println("Not Equal");
12 }
13 }
14 }
(a) Compile time error as we passed negative value in indexOf() method.
(b) Run time error as we passed negative value in indexOf() method.
(c) Program compiles and prints Equal when executed.
(d) Program compiles and prints Not Equal when executed.

Answers:1 (a)
No declaration is added, but When I run the example I found that the equals() method in the StringBuffer class is said that it is inherited from the Object class, and I think it didn’t override this method, as when I opened String class documentation it didn’t said that it inherits the equals() from the Object class, and it gave full description to it. And if this was true and the equals() method is the one inherited by the Object it is false, because it will return true only if the two reference denote the same object.

Answers:2 (c)
Options (a) and (b) will produce -5 and option 4 will not compile because the min method requires 2 parameters.

Answers:3 (a)
This is a bit of a sneaky one as the Math.random method returns a pseudo random number between 0 and 1, and thus option (c) is a plausible Answer. However the number returned is a double and so the compiler will complain that a cast is needed to convert a double to an int.

Answers:4 (b)
Compile time error:Casting needed to convert String to StringBuffer in line no. 5. [Mine opinion this will not work, to make it work  new StringBuffer(“A”), new StringBuffer(“B”) ]

Answers:5) AC
After concatenating "B" in str the result is not stored so it will not effect at all.Moreover main reason behind this is that Strings are immutable,it always return new object which means if we don't save the results then it will not effect the orignal string at all.

Answers:6) (c)
We can use negative argument in indexOf() and lastIndexOf() method.In such case it will start searching from zero.

Previous Home Next
Sponsored Ads
Sponsored Ads
Sponsored Ads
Sponsored Ads
Sponsored Ads
Interview Questions And Answers
Struts interview questions and answers (Subjective)
500 Java Objective Questions and Answer
Core Java Objective Questions And Answers
Core Java Subjective Questions And Answers
Core Java Interview Questions And Answers
Core Java Interview Questions and Answers (Subjective)
Core Java Interview Questions and Answers( Objective)
50 Servlet interview questions
155 Java Interview Questions
EJB Interview Questions and Answers(Subjective)
R4R,JSP Interview Questions and Answer(Subjective)
R4R,Java Servlets Interview Questions and Answers(Subjective)
Core Java Subjective ,Objective and Interview Questions And Answers
275 Core java interview questions
Java Objective Questions and Answer
Java Architect Interview Questions
Applet Interview Questions and Answers
Core Java example
Servlet Objective Questions And Answers
Servlet Subjective Questions And Answers
Servlet Interview Questions And Answers
JSP Objective Questions And Answers
JSP Subjective Questions And Answers
JSP Interview Questions And Answers
JDBC Objective Questions And Answers
JDBC Subjective Questions And Answers
JDBC Interview Questions And Answers
JDBC Interview questions and answers
Networking Interview questions and answers
Servlets Interview questions and answers
EJB Objective Questions And Answers
EJB Subjective Questions And Answers
EJB Interview Questions And Answers
Hibernate Objective Questions And Answers
Hibernate Subjective Questions And Answers
Hibernate Interview Questions And Answers
Spring Objective Questions And Answers
Spring Subjective Questions And Answers
Spring Interview Questions And Answers
Struts Objective Questions And Answers
Struts Subjective Questions And Answers
Struts Interview Questions And Answers
Ant Objective Questions And Answers
Ant Subjective Questions And Answers
Ant Interview Questions And Answers
PHP Objective Questions And Answers
PHP Subjective Questions And Answers
PHP Interview Questions And Answers 1
ASP.net Objective Questions And Answers
ASP.net Subjective Questions And Answers
ASP.net Interview Questions And Answers 1
ASP.net interview questions ,ASP.net interview answers,ASP.net interview questions and answers
PHP interview questions ,PHP interview answers,PHP interview questions and answers
Testing Objective Questions And Answers
Testing Subjective Questions And Answers
Testing Interview Questions And Answers
Ajax Tutorials
Ajax Objective Questions And Answers
Ajax Subjective Questions And Answers
Ajax Interview Questions And Answers
Linux Objective Questions And Answers
Linux Subjective Questions And Answers
Unix Subjective Questions And Answers
Unix Interview Questions And Answers
HR interview questions and answers
HR Interview Questions Tips
HR Objective Questions And Answers
HR Subjective Questions And Answers
HR Interview Questions And Answers
Learn C Language with in a day
 C /C++ Questions
C Objective Questions And Answers
C Subjective Questions And Answers
C Interview Questions And Answers
C Objective Interview Questions And Answers(10)
C Subjective Interview Questions And Answers(100) 
C syntax,semantics and simple programming questions(61) 

Linux Interview Questions And Answers
Unix Objective Questions And Answers
C Aptitude Questions(179)
C++ Interview Questions And Answers    
C++ Objective Questions And Answers
C++ Subjective Questions And Answers
C++ Interview Questions And Answers
C,C++ objective Interview Questions and answers
C Interview Questions And Answers( Objective and Subjective)
C Objective Interview Questions And Answers(10)

C Subjective Interview Questions And Answers(100)

C,C++ Interview Questions

35 C++ Interview Questions And Answers(Subjective)

109 C++ Interview Questions

Java Script Interview Question and Answer(1-10).
 Java Script Interview Question and Answer(11-20).
Java Script  Interview Question and Answer(21-30).
Java Script Interview Question and Answer(31-40).
Javascript Objective Questions And Answers
Javascript Subjective Questions And Answers
Javascript Interview Questions And Answers
MFC Interview Questions And Answers(Subjective)

MFC Interview Questions And Answers(Subjective)

ATL Interview Questions And Answers(Subjective)

COM DCOM Interview Questions And Answers(Subjective)

Win32API Interview Questions And Answers(Subjective)

ActiveX Interview Questions And Answers(Subjective)

R4R, VC++ AllOther Interview Questions And Answers(Subjective)

PL/SQL Interview Questions And Answers(Subjective)

152 PL/SQL Interview Questions And Answers(Subjective)

Asp Objective Questions And Answers
Asp Subjective Questions And Answers
Asp Interview Questions And Answers 1

VB Objective Questions And Answers

Contact US:

Your Name:


Your Email:

Message:

Comments:

Give Your Comments:


Advertiser PRIVACY POLICY ||User PRIVACY POLICY || R4R Group Srvices