Answers for "private class in java"

0

how to access private vairable in java method

public Class A{

   private String myData;

   public String getMyData(){
        return myData;
   }

   public void setMyData(String data){
        this.myData=data;
   }
}
Posted by: Guest on June-29-2020
0

private class in java

class Display {
 
   //Private nested or inner class 
   private class InnerDisplay {
      public void display() {
         System.out.println("Private inner class method called");
      }
   }
 
   void display() {
      System.out.println("Outer class (Display) method called");
      // Access the private inner class
      InnerDisplay innerDisplay = new InnerDisplay();
      innerDisplay.display();
   }
}
 
public class Main {
 
   public static void main(String args[]) {
      // Create object of the outer class (Display)
      Display object = new Display();
 
      // method invocation
      object.display();
   }
}
Posted by: Guest on July-28-2021

Code answers related to "private class in java"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language