Results 1 to 20 of 20
  1. #1
    mr idiot's Avatar
    mr idiot is offline Member
    Join Date
    Dec 2008
    Location
    Indramayu, Indonesia
    Posts
    12
    Rep Power
    0

    Default superclass and subclass

    Dear All,

    help me, this is my task from my teacher...please tell me script java which have one superclass and two subclasses?


    Thanks


    idiot newbie java

  2. #2
    Join Date
    Dec 2008
    Location
    Italy
    Posts
    79
    Rep Power
    0

    Default

    It's your homework. We can't do it for you, it makes no sense

    You shouldn't use forums to ask this sort of things. Whoever can find interesting what you're asking?

  3. #3
    CJSLMAN's Avatar
    CJSLMAN is offline Moderator
    Join Date
    Oct 2008
    Location
    Mexico
    Posts
    1,159
    Rep Power
    8

    Default Please clarify

    Please clarify your question.
    script java which have one superclass and two subclasses?
    The above statement makes no sense. Are you talking about:
    • JavaScript?
    • Java program?

    If this question has to do with Javascript, this is not the forum to ask. This is a Java developers forum.

    What is understandable is "superclass" and "subclass"... here is a link that may help understand:
    What Is Inheritance? (The Java™ Tutorials > Learning the Java Language > Object-Oriented Programming Concepts)

    Luck,
    CJSL
    Chris S.
    Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.

  4. #4
    mr idiot's Avatar
    mr idiot is offline Member
    Join Date
    Dec 2008
    Location
    Indramayu, Indonesia
    Posts
    12
    Rep Power
    0

    Smile For all

    Sorry, Script java is mymean syntax java for make program with superclass and subclass..


    Thanks

    idiot newbie java

  5. #5
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

  6. #6
    mr idiot's Avatar
    mr idiot is offline Member
    Join Date
    Dec 2008
    Location
    Indramayu, Indonesia
    Posts
    12
    Rep Power
    0

    Default

    In my program (Superclass and subclass) find error. Aproximately such as :

    this is Ngetest.java file

    public class Ngetest
    {
    public static void main(String [] Args)
    {
    // Menampilkan objek Tabung
    Tabung myTabung = new Tabung(5.0,2.0);
    System.out.println("Panjang Tabung : "+myTabung.getpanjang());
    System.out.println("Radius : "+myTabung.getRadius());
    System.out.println("Volume Tabung : "+myTabung.findVolume());
    System.out.println("Daerah Lingkaran: "+myTabung.findArea());
    }
    }


    public class Lingkaran
    {
    private double radius;
    Lingkaran(double r)
    {
    radius = r;
    }
    Lingkaran() { //Constructor
    radius = 1.0;
    }
    public double getRadius()
    {
    return radius;
    }
    public double findArea()
    {
    return radius*radius*3.14159;
    }
    }

    public class Tabung extends Lingkaran
    {
    private double panjang;
    public Tabung()
    {
    super();
    panjang = 1.0;
    }
    public Tabung(double r,double l)
    {
    super(r);
    panjang = l;
    }
    public double getpanjang()
    {
    return panjang;
    }
    public double findVolume()
    {
    return findArea() * panjang;
    }
    }



    and find error :

    C:\Java>javac Ngetest.java
    Ngetest.java:16:class Lingkaran is public, should be declared in a file Lingkaran.java
    public class class Lingkaran
    Ngetest.java:35:class Tabung is public, should be declared in a file Tabung.java
    public class Tabung extends Lingkaran

    2 errors

    C:\JAVA>
    please tell me about the errors?

    Thanks

    Idiot newbie java

  7. #7
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

  8. #8
    mr idiot's Avatar
    mr idiot is offline Member
    Join Date
    Dec 2008
    Location
    Indramayu, Indonesia
    Posts
    12
    Rep Power
    0

    Default

    Yes, it is in the same text file.










    thanks


    idiot newbie java

  9. #9
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    You cannot have multiple public classes in the same file. So remove the word public in every class, except the main class.

  10. #10
    mr idiot's Avatar
    mr idiot is offline Member
    Join Date
    Dec 2008
    Location
    Indramayu, Indonesia
    Posts
    12
    Rep Power
    0

    Default

    oh...the public class can't in the same text file.
    ok..I'll try it
    Thanks Erangga for your information.

    Idiot newbie java

  11. #11
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Quote Originally Posted by mr idiot View Post
    oh...the public class can't in the same text file.
    Multiple public class cannot have in the same text file. Only the main class must have the public access level.

  12. #12
    mr idiot's Avatar
    mr idiot is offline Member
    Join Date
    Dec 2008
    Location
    Indramayu, Indonesia
    Posts
    12
    Rep Power
    0

    Default

    what's it true?

    Ngetest.java

    public class Ngetest
    {
    public static void main(String [] Args)
    {
    // Menampilkan objek Tabung
    Tabung myTabung = new Tabung(5.0,2.0);
    System.out.println("Panjang Tabung : "+myTabung.getpanjang());
    System.out.println("Radius : "+myTabung.getRadius());
    System.out.println("Volume Tabung : "+myTabung.findVolume());
    System.out.println("Daerah Lingkaran: "+myTabung.findArea());
    }
    }


    public class Lingkaran
    {
    private double radius;
    Lingkaran(double r)
    {
    radius = r;
    }
    Lingkaran() { //Constructor
    radius = 1.0;
    }
    public double getRadius()
    {
    return radius;
    }
    public double findArea()
    {
    return radius*radius*3.14159;
    }
    }

    Lingkaran.java

    public class Lingkaran
    {
    private double radius;
    Lingkaran(double r)
    {
    radius = r;
    }
    Lingkaran() { //Constructor
    radius = 1.0;
    }
    public double getRadius()
    {
    return radius;
    }
    public double findArea()
    {
    return radius*radius*3.14159;
    }
    }


    Tabung.java

    public class Tabung extends Lingkaran
    {
    private double panjang;
    public Tabung()
    {
    super();
    panjang = 1.0;
    }
    public Tabung(double r,double l)
    {
    super(r);
    panjang = l;
    }
    public double getpanjang()
    {
    return panjang;
    }
    public double findVolume()
    {
    return findArea() * panjang;
    }
    }

    from the 3 files above please tell me :
    what's the superclass?
    and what's the subclass?
    what's a superclass have 2 subclasses?


    Thanks


    idiot newbie java

  13. #13
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Seems you don't know what's the supper class and sub class. Basically Java basis?

    So who written this code?

  14. #14
    mr idiot's Avatar
    mr idiot is offline Member
    Join Date
    Dec 2008
    Location
    Indramayu, Indonesia
    Posts
    12
    Rep Power
    0

    Smile

    I'm still confused different main class, superclass, and sub class.
    I think that superclass is Lingkaran.class, main class is Ngetes.class, and subclass is Tabung.class. What's it true?
    I just want to ensure that it's correct or not?




    Thanks


    newbie java

  15. #15
    mr idiot's Avatar
    mr idiot is offline Member
    Join Date
    Dec 2008
    Location
    Indramayu, Indonesia
    Posts
    12
    Rep Power
    0

    Default

    Thanks very much Mrs Eranga I'll always try learn java, becaus I'll want to know java programing more depth.
    I know that I dont know basic java programming but I'll learn it.



    thanks


    newbie java

  16. #16
    CJSLMAN's Avatar
    CJSLMAN is offline Moderator
    Join Date
    Oct 2008
    Location
    Mexico
    Posts
    1,159
    Rep Power
    8

    Default See link?

    @OP: did you read the link that I posted above? It clearly explains and shows what the difference is between superclass and subclass.

    Luck,
    CJSL
    Chris S.
    Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.

  17. #17
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Quote Originally Posted by mr idiot View Post
    Thanks very much Mrs Eranga I'll always try learn java, becaus I'll want to know java programing more depth.
    I know that I dont know basic java programming but I'll learn it.



    thanks


    newbie java
    Put some effort lol. Read a lot. That's the best you can achieve.

  18. #18
    mr idiot's Avatar
    mr idiot is offline Member
    Join Date
    Dec 2008
    Location
    Indramayu, Indonesia
    Posts
    12
    Rep Power
    0

    Wink

    Thanks very much for your support.

  19. #19
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

  20. #20
    mr idiot's Avatar
    mr idiot is offline Member
    Join Date
    Dec 2008
    Location
    Indramayu, Indonesia
    Posts
    12
    Rep Power
    0

    Smile

    the syntax superclass and subclass no found errors. becaus I had discared the word public (in class Lingkaran and class Tabung) in the same text file.


    public class Ngetest
    {
    public static void main(String [] Args)
    {
    // Menampilkan objek Tabung
    Tabung myTabung = new Tabung(5.0,2.0);
    System.out.println("Panjang Tabung : "+myTabung.getpanjang());
    System.out.println("Radius : "+myTabung.getRadius());
    System.out.println("Volume Tabung : "+myTabung.findVolume());
    System.out.println("Daerah Lingkaran: "+myTabung.findArea());
    }
    }


    class Lingkaran
    {
    private double radius;
    Lingkaran(double r)
    {
    radius = r;
    }
    Lingkaran() { //Constructor
    radius = 1.0;
    }
    public double getRadius()
    {
    return radius;
    }
    public double findArea()
    {
    return radius*radius*3.14159;
    }
    }

    class Tabung extends Lingkaran
    {
    private double panjang;
    public Tabung()
    {
    super();
    panjang = 1.0;
    }
    public Tabung(double r,double l)
    {
    super(r);
    panjang = l;
    }
    public double getpanjang()
    {
    return panjang;
    }
    public double findVolume()
    {
    return findArea() * panjang;
    }
    }
    main class is Ngetest
    superclass is Lingkaran
    subclass is Tabung.
    Thanks ...it's correct.

Similar Threads

  1. Replies: 1
    Last Post: 07-22-2008, 04:27 PM
  2. Subclass definition
    By Java Tip in forum java.lang
    Replies: 0
    Last Post: 04-23-2008, 08:03 PM
  3. subclass vs inner class
    By bugger in forum New To Java
    Replies: 1
    Last Post: 01-13-2008, 07:31 PM
  4. which class is superclass and subclass?
    By java_fun2007 in forum New To Java
    Replies: 0
    Last Post: 12-11-2007, 08:55 PM
  5. SubClass problems
    By ravian in forum New To Java
    Replies: 1
    Last Post: 11-19-2007, 05:54 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •