aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Questions from mock Exam !!! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Questions from mock Exam !!!" Watch "Questions from mock Exam !!!" New topic
Author

Questions from mock Exam !!!

sunil kathuria
Greenhorn

Joined: Jun 06, 2001
Posts: 24
q-1)
=====
import java.io.*;
class Super
{
int methodOne( int a, long b ) throws IOException
{ // code that performs some calculations
}
float methodTwo( char a, int b )
{ // code that performs other calculations
}
}
public class Sub extends Super
{
}
which of the following are legal method declarations to
add to the class Sub?
Assume that each method is the only one being added.
a) public static void main( String args[] ){}
b) float methodTwo(){}
c) long methodOne( int c, long d ){}
d) int methodOne( int c, long d ) throws ArithmeticException{}
e) int methodOne( int c, long d ) throws FileNotFoundException{}
the answer given are ---> a,b,e
but according to me 'd' is also valid method if we don't
declare 'e' in sub class so in this case we can choose
either d or e.
so pl.tell me the right answers and correct me if wrong
q-2)
=====
If raf is a RandomAccessFile, what is the result of compiling
and executing the following code?
raf.seek( raf.length() );
a) The code will not compile.
b) An IOException will be thrown.
c) The file pointer will be positioned immediately before the
last character of the file.
d) The file pointer will be positioned immediately after the
last character of the file.
answer given is -->d
it is little bit confusing me . i think ,answer may be 'a' as
"seek(long i)" method throws IoException and i know if a method
may throws Checked exception then it should be in try-catch block
or declared in throws clause of method.in this case there is no
try-catch block . so the code should not compile
d is correct if the code will be written in try-catch block.
pl. tell me the right answer

thanks in adv.
sunil
Axel Janssen
Ranch Hand

Joined: Jan 08, 2001
Posts: 2164
to 1) the method is declared in a SubClass. So you cannot throw checked Exceptions which are not thrown in the overriden method.
to 2) For me this is just a code snippet. You should put the line in try - catch if you use it in a program. But they just ask for the method-functionality.
hope this helps
Axel
Elizabeth Jacob
Greenhorn

Joined: Feb 19, 2001
Posts: 28
Hi Sunil,
For q1,i think u r right, since it clearly says to assume that each method is the only one being added.
For q2 ,i would assume that line of code is part of a try-catch block or a method that throws IOException. in the real exam u won't be confused like this.
Elizabeth.
Jyotsna Umesh
Ranch Hand

Joined: May 09, 2001
Posts: 94
Hi sunil,
For Ques. 1 I guess you are right. d option is one of the right ans. so ans. is a,b,d and e
For ques. 2 I feel ans. should be C becoz if the length of the file is 16 for eg., becoz of zero based starting it will point at 15 i.e. The file pointer will be positioned immediately before the last character of the file.
Please confirm if I am wrong.
Jyotsna
jim d
Greenhorn

Joined: Jun 28, 2001
Posts: 8
surely d is wrong, as a an overriding method cannot throw any exceptions other than that thrown by the overridden method. An arithmetic exception is not a subclass of an IO exception is it?
Elizabeth Jacob
Greenhorn

Joined: Feb 19, 2001
Posts: 28
Regarding the Q1, if an overridden method( in the sub class)throws a checked exception it has to be a subclass of the exception thrown in the superclass.Here in option d) an Arithmatic Exception is being thrown which is an 'unchecked' exception and hence it does'nt matter the fact that it is not a subclass of IOException.
Elizabeth.
Cameron Park
Ranch Hand

Joined: Apr 06, 2001
Posts: 371
What are checked Exceptions and unchecked Exceptions?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Questions from mock Exam !!!