GeeCON Prague 2014*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes  A question from MindQ 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 " A question from MindQ" Watch " A question from MindQ" New topic
Author

A question from MindQ

Kishore Pamu
Ranch Hand

Joined: Mar 18, 2001
Posts: 35
Consider the classes defined below:
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{}
i want to know the answer for this question.
i think it is b,d,e.but iam confused .

Kishore
Stevie Kaligis
Ranch Hand

Joined: Feb 04, 2001
Posts: 400
I think is :
a) public static void main( String args[] ){}
you can have two or more classes in the same FILE (file should have the same name of one of those), all classes can have the main method, but JVM will access main whose have the same NAME as a FILE. since main() is static, you can access each main class using nameClass.main(args);
b) float methodTwo(){} //it's overloading

d) int methodOne( int c, long d ) throws ArithmeticException{}
it's a RuntimeException
e) int methodOne( int c, long d ) throws FileNotFoundException{}
it's a subclass of IOException

stevie
Pam Doucette
Greenhorn

Joined: Mar 13, 2001
Posts: 27
I still don't understand why a) wouldn't be included as a legal method. The Sub class is the public class - so shouldn't it be the one that is the same as the file name and contain the main method? The main method declaration looks right to me, too.
Kishore Pamu
Ranch Hand

Joined: Mar 18, 2001
Posts: 35
Hi!stevie,
thanks for ur explanation
Jane Griscti
Ranch Hand

Joined: Aug 30, 2000
Posts: 3141
Hi Pam,
The <code>main()</code> method is legal; it will not cause a compile error if it's included in the Sub class.
You can use main() in any class; wether it's public or not. It's handled like any other method; just has the special status of being the first one the JVM looks for when you run a class.
Hope that helps.
------------------
Jane Griscti
Sun Certified Programmer for the Java� 2 Platform


Jane Griscti
SCJP, Co-author Mike Meyers' Java 2 Certification Passport
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: A question from MindQ