Sponsored Links

November 24, 2017

Constructor in Java

class Sample{
 private String girlName;
 public Sample(String name){
  girlName=name;
 }
 public void setName(String name){
  girlName=name;
 }
 public String getName(){
  return girlName;
 }
 public void displaydata(){
  System.out.printf("Name of the girl is %s", getName());
 }
 
}

public class ConstructorEx {
 public static void main(String args[]){
  Sample sampleObj=new Sample("priya");
  sampleObj.displaydata();
 }
}

No comments:

Post a Comment