• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

5 javaprepare questions

 
Ranch Hand
Posts: 144
Redhat Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Friends I recently gave the first sample test of Javaprepare
I am having a few doubts .... I have also mentioned my thinking on why I think a particular answer to be correct.
Which of the following is correct ? Select all correct answers.
A The native keyword indicates that the method is implemented in another language like C/C++.
B The only statements that can appear before an import statement in a Java file are comments.
C The method definitions inside interfaces are public and abstract. They cannot be private or protected.
D A class constructor may have public or protected keyword before them, nothing else.
The answer given is AB C
I say why B is correct package name comes even before the import statement.

When I am compiling the following code it gives Arithmatic Exception not found ???I wonder why ..... Hoewver teh answer it is giving is A D E
2 what will be the ouptut of following code
public class test {
public static void main(String args[]) {
int i=1, j=1;
try {
i++;
j--;
if(i/j > 1)
i++;
}
catch(ArithemticException e) {
System.out.println(0);
}
catch(ArrayIndexOutOfBoundsException e) {
System.out.println(1);
}
catch(Exception e) {
System.out.println(2);
}
finally {
System.out.println(3);
}
System.out.println(4);
}
}

a 0
b 1
c 2
d 3
e 4

Which of the following are legal array declarations. Select all correct answers.
a int i[5][];
b int i[][];
c int []i[];
d int i[5][5];
e int[][] a;
ANS:
BC And E
I thought that all of these ways are true.
if tehre is an argumentr like in Arrrays the no of elements must be defined then I will aks why E is correct.
4)
If a base class has a method defined as
void method() { }
Which of the following are legal prototypes in a derived class of this class.
Select all correct answers.
a void method() { }
b int method() { return 0;}
c void method(int i) { }
d private void method() { }
the correct ans are A and c
My presumtion was that D should also be correct as the messsage body is void and it also declares the method to be void.Addition of Private just means that it can be accessed in its own package. or its subclasses.
Q5) Name the collection interface used to represent collections that maintain unique elements.
My Answer was Maps however javaprepare gives answer as Set
I saw in KM book and It seems that both allow only unique elemtns.
if both the answers are corre
 
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sunil,
1. Your thought was right. Answers are A,C
2. Answers are A,D,E. There was a small error in the program. ArithmeticException was misspelled as ArithemticException
3. Answers are B,C,E. You can't put size in declaration. a should have been int i[][]; d should have been int i[][].
4. Answers are A, C. You cannot override the method to more restrictive access. Problem with private access modifier.
5. Please refer one more book for this
[This message has been edited by venu gopal (edited January 19, 2001).]
 
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I'll try my best to answer your Qns one by one.
#1:
You are quite right.The correct choices are A & C.Package statements can appear before import statements.So B cannot be correct.Also,I want to bring to your notice that the answers that javaprepare has provided is correct afterall-if you can scrutinise the punctuations in the sentence.
"a, c. b is not correct. A package statement may appear before an import statement. "
#2:
The correct reponses are A,D & E(0,3,4 get printed).It's not an Arithmetic Exception,but actually a 'spelling'Exception!!!I'm afraid.
catch(ArithemticException e) {
System.out.println(0);
}
Now check the spelling for Arithmetic in the above lines of code-your program's gonna work fine.
#3:
Choices A&D are ruled out b'cos it is not possible to specify array size in a declaration.You should do the same while constructing it using the 'new' operator.Choice E is quite right.It is perfectly legal to declare a multidimensional array,this way.
Check KM page #91.
#4:
D is NOT correct.
It is quite obvious that in the base class the method has the default access(friendly).Now declaring it as private in the derived class is restricting its access more.This is against the rules.Always the access should be more and NOT lesser than it's access in the base class.
private->friendly->protected->public-This is the correct access order.
#5:
The correct Ans is Set & not Map!
Check page# 325 in KM
Conceptually a map is not a collection.A map does not contain elements.It contains mappings from a set of key objects to a set of value objects...
Hope I've cleared your doubts.Good Luck!
Priya Kannan

Originally posted by sunil choudhary:
Friends I recently gave the first sample test of Javaprepare
I am having a few doubts .... I have also mentioned my thinking on why I think a particular answer to be correct.
Which of the following is correct ? Select all correct answers.
A The native keyword indicates that the method is implemented in another language like C/C++.
B The only statements that can appear before an import statement in a Java file are comments.
C The method definitions inside interfaces are public and abstract. They cannot be private or protected.
D A class constructor may have public or protected keyword before them, nothing else.
The answer given is AB C
I say why B is correct package name comes even before the import statement.

When I am compiling the following code it gives Arithmatic Exception not found ???I wonder why ..... Hoewver teh answer it is giving is A D E
2 what will be the ouptut of following code
public class test {
public static void main(String args[]) {
int i=1, j=1;
try {
i++;
j--;
if(i/j > 1)
i++;
}
catch(ArithemticException e) {
System.out.println(0);
}
catch(ArrayIndexOutOfBoundsException e) {
System.out.println(1);
}
catch(Exception e) {
System.out.println(2);
}
finally {
System.out.println(3);
}
System.out.println(4);
}
}

a 0
b 1
c 2
d 3
e 4

Which of the following are legal array declarations. Select all correct answers.
a int i[5][];
b int i[][];
c int []i[];
d int i[5][5];
e int[][] a;
ANS:
BC And E
I thought that all of these ways are true.
if tehre is an argumentr like in Arrrays the no of elements must be defined then I will aks why E is correct.
4)
If a base class has a method defined as
void method() { }
Which of the following are legal prototypes in a derived class of this class.
Select all correct answers.
a void method() { }
b int method() { return 0;}
c void method(int i) { }
d private void method() { }
the correct ans are A and c
My presumtion was that D should also be correct as the messsage body is void and it also declares the method to be void.Addition of Private just means that it can be accessed in its own package. or its subclasses.
Q5) Name the collection interface used to represent collections that maintain unique elements.
My Answer was Maps however javaprepare gives answer as Set
I saw in KM book and It seems that both allow only unique elemtns.
if both the answers are corre


 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Answer to question 5)
Set is the only interface, concrete implementations of which allow only unique elements.
Map does not maintain unique elements because u can add the same element multiple times with different keys. However, it's unique on keys, which means that one key can be at most once in a map(but elements/values can be repeated!!).
rgds,
Roshan
 
reply
    Bookmark Topic Watch Topic
  • New Topic