File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Doubt in Sarga's Test1

 
swati bannore
Ranch Hand
Posts: 201
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!!
I wld like to focus light on errors in the Sarga's test1.The errors are in the answers.I shall write the question and ans given by Sarga and the ans I feel right.
Please Correct me If I am Wrong
Thanx

Q.1)Given the following class definition:
class A {
protected int i;
A(int i) {
this.i = i;
}
}
Which of the following would be a valid inner class for this class?
Select all valid answers.
a) class B {
}
b) class B extends A {
}
c) class B {
B() {
System.out.println("i = " + i);
}
}
d) class B {
class A {
}
}
e) class A {
}
Sarga's Answer: A
My Answer : A & C.Option C is an example of valid inner class
---------------------------------------------------------------------------------
26) A sample question provided by Sun
Which correctly create an array of five empty Strings?
A.String a [] = new String [5];
for (int i = 0; i < 5; a[i++] = "");
B.String a [] = {"", "", "", "", ""};
C.String a [5];
D.String [5] a;
E.String [] a = new String [5];
for (int i = 0; i < 5; a[i++] = null);

Sarga' Answer : A & B
My Answers : A,B and E
Cause in option A,array is created and filled with null values.So in option E ,it does the same thing. In any case,array will have null values.
 
Jane Griscti
Ranch Hand
Posts: 3141
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Sarga,
Q1. You're right. Answer C is a valid inner class.
Q2. A 'null' is not the same as an empty string. Answer E is incorrect. You'd be creating an array of null objects, not empty strings.
Hope that helps.
------------------
Jane Griscti
Sun Certified Programmer for the Java� 2 Platform
 
swati bannore
Ranch Hand
Posts: 201
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanx,
But does that mean empty string array is not filled with nulls?
 
Thomas Paul
mister krabs
Ranch Hand
Posts: 13974
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
An empty String array is filled with empty Strings
"" is not equal to null
Try this:
String s = "";
s = s.trim();
Then try this:
String s = null;
s = s.trim();

------------------
Moderator of the Programmer Certification Forums
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic