Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7943269
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T00:13:20+00:00 2026-06-04T00:13:20+00:00

I cannot grasp the usage of those constructors. I understand that one is as

  • 0

I cannot grasp the usage of those constructors.

I understand that one is as follows:

public book(){
private string author;
private string title;
private int reference;
}

And a parametrised constructor is as follows:

public book( string author, string title, int reference){ 
}

However how would this be used in a main method?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T00:13:22+00:00Added an answer on June 4, 2026 at 12:13 am

    There are three ways you can have a constructor:

    1) You declare a no-parameter one

    .

    public class book
    {
      string author;
      string title;
      int reference;
      public book() {
        // initialize member variables with default values
        // etc.
      }
    }
    

    2) You declare one with parameters

    .

    public class book
    {
      string author;
      string title;
      int reference
      public book(string author, string title, int reference) {
        // initialize member variables based on parameters
        // etc.
      }
    }
    

    3) You let the compiler declare one for you — this requires you do not declare one of your own. In this case the member variables will be provided a default value based on their type (essentially their no-parameter constructor called)

    You can mix options 1) and 2), but 3) is stand-alone (cannot mix it with any of the other two). You can also have more than one constructors with parameters (the parameter types/numbers must be different)

    An example use:

    public static void main(String[] args) {
      String author = ...;
      String title = ...;
      int ref = ...;
      book book1 = new book(); // create book object calling no-parameter version
      book book2 = new book(author, title, ref); // create book object calling one-parameter
                                    // (of type String) version
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm stumbling over some basic concepts, that I cannot grasp. I hope, somebody can
Cannot bind the CollectionViewSource DocProps is a public property public ObservableCollection<DocProp> DocProps1 DataContext is
I cannot understand the calculation 66 ⊕ fa = 9c. The sum is clearly
Facebook cannot grasp my og:image files and I have tried every usual solution. I'm
I have a class method that deals with dates: public function setAvailability(DateTime $start, DateTime
Ran across this, but I cannot quite grasp it, especially beginning with the LIMIT
Cannot seem to grasp the concept of PageLink attributes for EpiServer listing controls. I
I have been rereading http://cm.bell-labs.com/who/ken/trust.html and I cannot seem to grasp the concept in
Cannot access a disposed object. Object name: 'System.Net.Sockets.TcpClient'. I don't understand why it happen
need some advice on this one as im struggling abit and cannot figure it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.