• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

jqplus

 
Vivek Shrivastava
Ranch Hand
Posts: 277
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI,
I am confuse little bit with these questions, these are from jqplus mock exam.
Q#1
if u cerate a List using the following line of code
java.awt.List list = new List();
which of the given statement are correct?
1. It will not allow multiple selections
2. The list has four visible items.
3. A vertical scroll bar will be added automatically if needed.
4. A list cannot be constructed this way.
5. None of the above.
given answer 1,2,3. i dont have idea about '2'. is it correct?
Q#2
How can u declare variable 'i' so that it is not visible outside the package 'test'
package test;
class Test
{
XXX int i;
/* Lots of code*/
}
1. private
2. public
3. protected
4. no access modifer.
given answer is 1,4. i do agree with '4' but i don't think '1' is correct answer.
please explain it to me.

vivek
 
Tushar Kansara
Ranch Hand
Posts: 38
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Must be a error in the exam, for the second question variable to be hidden outside the package actually means accessibility of the class itself & then the variable.
Public is out of question & so is private What remains is protected & friendly. As much as I know protected allows access within the package and all the subclasses irrespective of the package they reside in hence the correct answer i suppose is Friendly.
Friends correct me if i am wrong.
The First question I have checked the Java API. The List() constructor by default creates 4 visible lines with multiselection mode disabled, hence the correct answer u have guessed it is 1 & 2. I am not sure about option 3.
Regards
Tushar Kansara
------------------
 
Vivek Shrivastava
Ranch Hand
Posts: 277
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I
am still not clear with question one. please do help me.
vivek
 
Rahul Mahindrakar
Ranch Hand
Posts: 1868
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The question does not talk of accessability within the package as such the variable can be private. However if the variable is public or protected it would be accessible outside the package. Thus the answers are correct.
Regds.
Rahul
 
Anonymous
Ranch Hand
Posts: 18944
  • 0
  • send pies
  • Quote
  • Report post to moderator
Vivek,
When the java.awt.List is created using the no argument constructor, the default behaviour is to create four visible lines and default selection disabled.
I have no idea, why the number 4 was chosen. But I guess you will just have to remember this point for the exam.
Rgds,
Shashank
 
Harry Chawla
Ranch Hand
Posts: 97
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
RHE mentions on page 323, second sentence under List heading:
"If a list contains more items than it can display, it acquires a vertical scroll bar"
What I infer from it is that if required, it acquires vertical scroll bar.
Thanks.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic