wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes 4 quest diffulties please help Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "4 quest diffulties please help" Watch "4 quest diffulties please help" New topic
Author

4 quest diffulties please help

Abdul Latif
Ranch Hand

Joined: Jul 18, 2001
Posts: 89
which are the correct forms of Overloading Constructors for the
class hai?

a. public void hai(int a)
b. hai(int a,int b)
c. public hai(int a)
d. int hai(int c, int d)
e. int hai()
f. int hai(String s)
according to me is b & c
but the ans is a & b.
_________________________________________________________________
What is the modifier that is used for a variable in the class to be accessed in subclass only?

A. public
B. none
C. protected
D. private
the ans is protected but protected does not have sub class access but also package access
i think the question is poorly worded.
_________________________________________________________________
class sreejith
2. {
3. public static void main(String args[])
4. {
5. String s="hello";
6. String s1="hello";
7. System.out.println(s1);
8. String s3=s1;
9. s1=null;
10. s=null;
11. }
Which line the garbage collector will invoke first?

a. 9
b. 10
c. never
The ans says c
but i say it is 10, correct me if iam wrong
_________________________________________________________________
Which of the following is used to find max of 2 numbers given?
a. max()
b. Math.max();
c. None of the above.
the ans says b , but there is no version of max() which takes no arguments so the ans is c.
Am i right
Ragu Sivaraman
Ranch Hand

Joined: Jul 20, 2001
Posts: 464
Originally posted by Abdul Latif:
which are the correct forms of Overloading Constructors for the
class hai?

a. public void hai(int a)
b. hai(int a,int b)
c. public hai(int a)
d. int hai(int c, int d)
e. int hai()
f. int hai(String s)
according to me is b & c
but the ans is a & b.
_________________________________________________________________
What is the modifier that is used for a variable in the class to be accessed in subclass only?

A. public
B. none
C. protected
D. private
the ans is protected but protected does not have sub class access but also package access
i think the question is poorly worded.
_________________________________________________________________
class sreejith
2. {
3. public static void main(String args[])
4. {
5. String s="hello";
6. String s1="hello";
7. System.out.println(s1);
8. String s3=s1;
9. s1=null;
10. s=null;
11. }
Which line the garbage collector will invoke first?

a. 9
b. 10
c. never
The ans says c
but i say it is 10, correct me if iam wrong
_________________________________________________________________
Which of the following is used to find max of 2 numbers given?
a. max()
b. Math.max();
c. None of the above.
the ans says b , but there is no version of max() which takes no arguments so the ans is c.
Am i right

Q1: In my opinion the answers are a,b,c
Although a and c cant be overloaded to-gether
But they can appear seperate with b
Poorly worded IMO
Q2: protected
Q3: Ans: Never. GC cant be predicted
Q4: Ans C: max() is not a method in Math class
But they are static
so programmatically Math.max(int a, int b) would be correct
Ragu
Valentin Crettaz
Gold Digger
Sheriff

Joined: Aug 26, 2001
Posts: 7610
Q1:
you are right answers b and c are correct. a is wrong since constructors do not return any value.
Q2:
right again, the question is poorly worded, BUT since they ask which modifier is to be used to allow a subclass to access a member variable in the superclass, protected is right. none is right too though!
Q3:
c seems to be the right answer here since s is created using a String literal which will be kept in the private String pool even after no references to that literal are existing. Instead if s was created with the following statement
String s = new String("hello);
then the garbage collector would be invoked after line 10 because the String is created dynamically without caring about what is available in the String pool (i.e. a new String is created anyway)
Q4:
right again, the question is poorly worded and Math.max() takes two arguments and returns the maximum of both arguments.
Anyone any insights ?

------------------
Valentin Crettaz
Sun Certified Programmer for Java 2 Platform


SCJP 5, SCJD, SCBCD, SCWCD, SCDJWS, IBM XML
[Blog] [Blogroll] [My Reviews] My Linked In
Ragu Sivaraman
Ranch Hand

Joined: Jul 20, 2001
Posts: 464
Q1: I am sorry i got little excited
a is not the correct answer
Yin Ming
Ranch Hand

Joined: Oct 12, 2001
Posts: 41
maybe we must guest whats the author of these questions meaning so that we could make the answers.
q1: all methods with return type are methods but not constructors. so i think its b & c
q3: all the String type variables point to the same object: the String literal "hello". regardless whether the string literal can be collected, this literal object is refered by s3 even after line 10. so nothing will be collected.
Nain Hwu
Ranch Hand

Joined: Sep 16, 2001
Posts: 139
Val,
Q2: Only protected is the right answer. None is not right answer.
Since the question is asking "accessed in subclass only". If
no modifiers are declared, the variable would have default (package) accessibility. This will make the variable accessible to any class in the package, not limited to subclass.

Q2:
none is right too though!

Q3: Bad wording:

Which line the garbage collector will invoke first?

"invoke the code"??? GC will never invoke the code!
Valentin Crettaz
Gold Digger
Sheriff

Joined: Aug 26, 2001
Posts: 7610
Nain,
I'd like you to remember (you know that probably) that protected accessibility also offers the access to all classes of a package which may not be subclasses. The question says subclasses only, so this is definitely bad wording, I think you agree on that !

------------------
Valentin Crettaz
Sun Certified Programmer for Java 2 Platform
Nain Hwu
Ranch Hand

Joined: Sep 16, 2001
Posts: 139
Val,
I agree with you on protected modifier. Thanks for reminding
me.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: 4 quest diffulties please help
 
Similar Threads
voodoo exam_1 question
confused
Quession on if(){} and so on
few doubts
two Garbage Collection Quetion!!