aquaballoon

Java - Access to Private of Member Data

Jul 14th, 2013
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.66 KB | None | 0 0
  1. package com.peter.car;
  2.  
  3. import com.peter.parts.Color;   // importing from package from com.peter.parts
  4.  
  5. public class Main {
  6.  
  7.     public static void main(String[] args) {
  8.  
  9.         String paint = "Red Color";
  10.         Color ObColor = new Color(paint);    // Constructor
  11.        
  12.         System.out.println(ObColor.getColor());
  13.                 System.out.println(ObColor.paint1);
  14.     }
  15. }
  16.  
  17. --------------------------------------------->
  18. package com.peter.parts;
  19.  
  20. public class Color {
  21.    
  22.     private String paint;
  23.     public String paint1 = "Orange Color";
  24.    
  25.     public Color(String paint){        // Constructor
  26.         this.paint = paint;
  27.     }
  28.    
  29.     public String getColor(){
  30.         return paint;
  31.     }
  32.  
  33. }
Advertisement
Add Comment
Please, Sign In to add comment