DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2
  1. #1
    Join Date
    Oct 2005
    South Africa

    Exclamation Java class IMPORTANT question

    Hi I just wanted to know the following:

    When creating a class that inherits its objects and methods etc... from another class, you must create a constructer that uses super();

    import Aclassfile.*;

    public class stuff
    public stuff(); //(<<<the constructer method)

    and then u use normal methods that perform specific functions.But what happens when i use a normal class file, such as java.math.*; then must i still create a constructor method with the super(); code???

    eg: how do i create a class file that will ask the user do imput a double and then the program will find the sin, cos and tan of the inputted double, i have tried but am totally confused...please help!!!

  2. #2
    Join Date
    Nov 2004
    The call to super() is not required, it will be invoked prior to the code in the
    descendant's constructor, povided that the superclass has a default (no parameters)
    constructor. If the superclass has no default constructor you have to implement
    your subclass so it calls one of the superclass' constructors as the first
    statement in your constructor(s).

    java.math is a package, java.lang.Math is a final class and cannot be
    extended, so in your case you can make yourself a plain (Object descendant) class
    that uses the java.Math class methods like static methods (double a=Math.sin(angle))
    eschew obfuscation

Similar Threads

  1. Replies: 2
    Last Post: 06-14-2006, 03:16 PM
  2. Re: C++ vs Java
    By Michael in forum Java
    Replies: 2
    Last Post: 12-31-2002, 04:55 PM
  3. executing java class files
    By karthik.s in forum Java
    Replies: 4
    Last Post: 12-13-2000, 06:24 AM
  4. Calling base class methods
    By GR in forum Java
    Replies: 1
    Last Post: 11-09-2000, 05:38 PM
  5. Re: VB vs. Visual Age for Java
    By JJ in forum Enterprise
    Replies: 1
    Last Post: 07-06-2000, 04:50 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
Latest Articles
Questions? Contact us.
Web Development
Latest Tips
Open Source

   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.