public
// Java program using the public modifier public class OnePublicClass { public static void main( String[ ] args ) { int x = 10; DefaultClass myObj = new DefaultClass( x ); myObj.display( myObj.x ); } } class DefaultClass { // a member variable int x = 5; // a constructor public DefaultClass( int x ) { x = x; } // a member method public void display( int x ) { System.out.print( x ); } }
// Java program using the public modifier public class TwoPublicClass { public static void main( String[ ] args ) { int x = 10; DefaultClass myObj = new DefaultClass( x ); myObj.display( myObj.x ); } } public class DefaultClass { // a member variable int x = 5; // a constructor public DefaultClass( int x ) { x = x; } // a member method public void display( int x ) { System.out.print( x ); } }