Jxam
posted 25 years ago
Hi ,
following questions are from jxam mock exam.
Q#1
Given the following definition:
String s = null;
Which code fragment will cause an exception of type NullPointerException to be thrown.
1. if ((s != null) & (s.length()>0))
2. if ((s != null) && (s.length()>0))
3. if ((s != null) | (s.length()>0))
4. if ((s != null) | | (s.length()>0))
5. none
given answer is 1,2,3,4.
i am sure '2' is not a valid answer. please do varify it.
Q#2
Which of the following statements are true regarding inner classes.
1. Variables defined inside inner classes cannot be static.
2. Variables defined inside inner classes cannot be static unless the inner class itself is static.
3. Non-static inner classes (which are not defined in a method) have access to all class and instance variables, regardless of the access qualifier of those variables.
4. An inner class can actually be a subclass of the outer class
5. Inner classes can be declared as private. Top level, outer classes cannot.
given answer is 2,3,4,5. but what is wrong with '1'.
please explain it to me.
vivek
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Hi ,
following questions are from jxam mock exam.
Q#1
Given the following definition:
String s = null;
Which code fragment will cause an exception of type NullPointerException to be thrown.
1. if ((s != null) & (s.length()>0))
2. if ((s != null) && (s.length()>0))
3. if ((s != null) | (s.length()>0))
4. if ((s != null) | | (s.length()>0))
5. none
given answer is 1,2,3,4.
i am sure '2' is not a valid answer. please do varify it.
Q#2
Which of the following statements are true regarding inner classes.
1. Variables defined inside inner classes cannot be static.
2. Variables defined inside inner classes cannot be static unless the inner class itself is static.
3. Non-static inner classes (which are not defined in a method) have access to all class and instance variables, regardless of the access qualifier of those variables.
4. An inner class can actually be a subclass of the outer class
5. Inner classes can be declared as private. Top level, outer classes cannot.
given answer is 2,3,4,5. but what is wrong with '1'.
please explain it to me.
vivek
posted 25 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
You are right Vivek, for Q1)
choice 2 can be compiled and run without error as it evaluates only the Right Handside of the expression and returns false.
choice 2 can be compiled and run without error as it evaluates only the Right Handside of the expression and returns false.
posted 25 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
What does option 3 within question 2 mean? I did not understand Non Static Inner class (not within a method).
I feel Non Static Inner class whether within or outside a method can access the class and instance variables.
I feel Non Static Inner class whether within or outside a method can access the class and instance variables.
Sun Certified Java Programmer<BR>Oracle Certified DBA
posted 25 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
I agree with you in Q1
1. Variables defined inside inner classes cannot be static.
True. From JLS: Inner classes may not declare static members, unless they are compile-time constant fields. Inner classes may inherit static members that are not compile-time constants.
2. Variables defined inside inner classes cannot be static unless the inner class itself is static.
True. From JLS: Nested classes that are not inner classes may declare static members freely.
3. Non-static inner classes (which are not defined in a method) have access to all class and instance variables, regardless of the access qualifier of those variables.
True, because you have an associated outer class with every inner that is not static, remember that static nested classes can�t access non-static members of it�s outer class
4. An inner class can actually be a subclass of the outer class
I read in some place that this is false, but it compiles without problem. I didn�t find any futher documentation about this topic.
5. Inner classes can be declared as private. Top level, outer classes cannot.
True
[This message has been edited by Marcela Blei (edited August 17, 2000).]
1. Variables defined inside inner classes cannot be static.
True. From JLS: Inner classes may not declare static members, unless they are compile-time constant fields. Inner classes may inherit static members that are not compile-time constants.
2. Variables defined inside inner classes cannot be static unless the inner class itself is static.
True. From JLS: Nested classes that are not inner classes may declare static members freely.
3. Non-static inner classes (which are not defined in a method) have access to all class and instance variables, regardless of the access qualifier of those variables.
True, because you have an associated outer class with every inner that is not static, remember that static nested classes can�t access non-static members of it�s outer class
4. An inner class can actually be a subclass of the outer class
I read in some place that this is false, but it compiles without problem. I didn�t find any futher documentation about this topic.
5. Inner classes can be declared as private. Top level, outer classes cannot.
True
[This message has been edited by Marcela Blei (edited August 17, 2000).]
posted 25 years ago
Are you not contradicting yourself? 2 of Q2 is right?
Savithri
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Originally posted by Marcela Blei:
I agree with you in Q1
Q2) I think that answer 1 is right and 2 is wrong
2. Variables defined inside inner classes cannot be static unless the inner class itself is static.
True. From JLS: Nested classes that are not inner classes may declare static members freely.
Are you not contradicting yourself? 2 of Q2 is right?
Savithri
Marcela Blei
Ranch Hand
Posts: 477
posted 25 years ago
Yes, you are right, i missed a correction on myself. I edited the message, sorry.
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Originally posted by Savithri Devaraj:
Are you not contradicting yourself? 2 of Q2 is right?
Savithri
Yes, you are right, i missed a correction on myself. I edited the message, sorry.
posted 25 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Hi ,
Which of the following statements are true regarding inner classes.
1. Variables defined inside inner classes cannot be static.
Ans: False
Explanation:
Inner classes includes:
- static inner classes
( Variables defined inside a static
inner classes can be static.)
- non static inner classes
(Variables defined inside a non static inner
classes cannot be static.)
So we can't generalize "1. Variables defined inside
inner classes cannot be static".
We can only say " 2. Variables defined inside inner
classes cannot be static unless the inner class
itself is static."
That is why
- Option 1 is false
- Option 2 is true.
Hope this may help,
Which of the following statements are true regarding inner classes.
1. Variables defined inside inner classes cannot be static.
Ans: False
Explanation:
Inner classes includes:
- static inner classes
( Variables defined inside a static
inner classes can be static.)
- non static inner classes
(Variables defined inside a non static inner
classes cannot be static.)
So we can't generalize "1. Variables defined inside
inner classes cannot be static".
We can only say " 2. Variables defined inside inner
classes cannot be static unless the inner class
itself is static."
That is why
- Option 1 is false
- Option 2 is true.
Hope this may help,
| I don't like that guy. The tiny ad agrees with me. The new gardening playing cards kickstarter is now live! https://www.kickstarter.com/projects/paulwheaton/garden-cards |






