File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Mock Exam Errata and the fly likes Doubt in Sarga's Test1 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Mock Exam Errata
Bookmark "Doubt in Sarga Watch "Doubt in Sarga New topic

Doubt in Sarga's Test1

swati bannore
Ranch Hand

Joined: Oct 18, 2000
Posts: 201
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

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.

Swati Kale
Jane Griscti
Ranch Hand

Joined: Aug 30, 2000
Posts: 3141
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

Jane Griscti
SCJP, Co-author Mike Meyers' Java 2 Certification Passport
swati bannore
Ranch Hand

Joined: Oct 18, 2000
Posts: 201
But does that mean empty string array is not filled with nulls?
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
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

Associate Instructor - Hofstra University
Amazon Top 750 reviewer - Blog - Unresolved References - Book Review Blog
I agree. Here's the link:
subject: Doubt in Sarga's Test1
It's not a secret anymore!