Wednesday 25 November 2015

Java Tutorial : Java Access modifiers private and public


Click here to watch in Youtube : 
https://www.youtube.com/watch?v=SotFxl07eAM&list=UUhwKlOVR041tngjerWxVccw

Student.java
public class Student
{
    /*
     * public modifier — the field is accessible from all classes.
     */
    public String name;
    
    /*
     * private modifier—the field is accessible only within its own class.
     */
    private int age;

}
StudentDemoTest.java
public class StudentDemoTest
{

    public static void main(String[] args)
    {
        Student student = new Student();
        student.name = "Dave";
        student.age = 23;
    }

}
Output
Exception in thread "main" java.lang.Error: Unresolved compilation problem: 
    The field Student.age is not visible

    at StudentDemoTest.main(StudentDemoTest.java:8)
Click the below link to download the code:
https://sites.google.com/site/javaee4321/java/AccessModifiersDemoPrivate-PublicApp.zip?attredirects=0&d=1

Github Link:
https://github.com/ramram43210/Java/tree/master/BasicJava/AccessModifiersDemoPrivate-PublicApp

Bitbucket Link:
https://bitbucket.org/ramram43210/java/src/2f20a20e875ab6e7de15adc0041c373263d61c3b/BasicJava/AccessModifiersDemoPrivate-PublicApp/?at=master

See also:
  • All JavaEE Viedos Playlist
  • All JavaEE Viedos
  • All JAVA EE Links
  • Servlets Tutorial
  • All Design Patterns Links
  • JDBC Tutorial
  • Java Collection Framework Tutorial
  • JAVA Tutorial
  • No comments:

    Post a Comment