Java parameterized constructor

Java Programming Java8Object Oriented Programming

Yes! it is supported. A constructor with arguments is called the parameterized constructor. It is used to initialize an object with given values. 

example

Live Demo

public class Tester {
 
   private String message;
 
   public Tester(String message){
      this.message = message;
   }
 
   public String getMessage(){
      return message ;
   }
 
   public void setMessage(String message){
      this.message = message;
   }
 
   public static void main(String[] args) {  
      Tester tester = new Tester("Welcome");
      System.out.println(tester.getMessage());  
   }
}   

Output

Welcome
raja
Published on 22-Apr-2018 20:14:45
Advertisements