• 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

A question from MindQ

 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 .
 
Ranch Hand
Posts: 400
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi!stevie,
thanks for ur explanation
 
Ranch Hand
Posts: 3141
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
There is no greater crime than stealing somebody's best friend. I miss you tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic