Java – public class constructor [duplicate]

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 😉

Leave a Comment