aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes 5 javaprepare questions Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "5 javaprepare questions " Watch "5 javaprepare questions " New topic
Author

5 javaprepare questions

sunil choudhary
Ranch Hand

Joined: Nov 10, 2000
Posts: 141

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


"Learning is weightless, a treasure you can always carry easily." -Chinese Proverb
venu gopal
Ranch Hand

Joined: Nov 21, 2000
Posts: 40
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).]
Priya Kannan
Ranch Hand

Joined: Jan 19, 2001
Posts: 72
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

RoshanDawrani
Greenhorn

Joined: Jan 21, 2001
Posts: 16
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: 5 javaprepare questions
 
Similar Threads
Question on exception throwing
jargon exam
try/catch/finally
mock questions from java prepare
Exception