Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Mar 2011
    Posts
    41
    Thanks
    16
    Thanked 0 Times in 0 Posts

    Define a constructor

    how to create a constructor for our class with no parameters, constructor has to show
    Some sentence:
    "You are here!"
    Last edited by Datis; 03-30-2012 at 05:00 PM.

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    PHP Code:
    public YourClassName()
    {
        
    System.out.println("You are here!");


  • Users who have thanked Fou-Lu for this post:

    Datis (03-31-2012)

  • #3
    New Coder
    Join Date
    Mar 2011
    Posts
    41
    Thanks
    16
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Fou-Lu View Post
    PHP Code:
    public YourClassName()
    {
        
    System.out.println("You are here!");


    public class test {

    public test () {
    System.out.println("You are here!");}

    public static void main (String[] args)


    {


    }

    }

    I cant print my sentence, why?

  • #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    You haven't invoked the class 'test'. You need to call a new test(); in the main method.


  •  

    Posting Permissions

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