-6

I need explain on class. What is constructor and how write it and what is public namecllase(){ Here all the variable } How this is call?

Thank you

1

1 Answer 1

0

Ok simple example You make one class that name is : Demo

class Demo{

}

Inner you make a constructer, that is what you call if you need it... look below

class Demo{
  public Demo(int num, String str)
  {
       int num;
       String str = "This is a parameterized constructor with number ";
       System.out.println(str + num);
  }
}      

You can make more of them for example an empty constructer or with a defined value Now you can call your class with that constructer something like that :

public static void main(String args[]){
    String strrrrr = "This is your value of variable int"
    int i = 99;
    Demo demo = new Demo(strrrrr, i);
}

So you can see that you console gives you message with your variable String strrrrr and int i I hope I could help you ;)

Sign up to request clarification or add additional context in comments.

2 Comments

thank you, it's was helpful.
Only one thing I did not understand, if i have constructer Demo i need to write Before the constructor >> public/private int =0; and public/private String=""; ? because I've seen other codes listed in this, Is it necessary and if it changed anything? And what is meant in general?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.