Search 800 + Posts

Feb 10, 2011

Simple Java Class with Public and Private Methods

package java_test;

public class srt {
    public srt() {
   System.out.println("empty Constructor without Parametyeres in Class srt");    
     //   super();
     }
    public srt( int a){
    System.out.println("Constructor with Parameter in Class srt- "+a);
    }
    //public method
    public void pub_method(){
      System.out.println("I am Public Method in Class Srt");
    }
   
    //Private Method
    private void pvt_method() {
      System.out.println("I am private method srt");
    }


public static void main(String[] args) {
int a;
  System.out.println("Main"); 
  srt myclass = new srt();  //Call to Default Constructor
  srt myclass_var = new srt(1972);  //call to Constructor with Parameter
  myclass.pub_method(); //call to public method
  myclass.pvt_method(); //call to Private method
}
}

No comments:

Post a Comment