EduLearn - Online Education Platform

Welcome to EduLearn!

Start learning today with our wide range of courses taught by industry experts. Gain new skills, advance your career, or explore new interests.

Browse Courses

Access Modifiers:

 

public–>Accessible everywhere

 

private–>only within the same class

 

protected–>same class,same package,sub class,not possible in other packages

 

default—->same class,same package,not possible in subclass & other packages)

 

(no keyword)

————————————-

class Public

{

public int x=10;

 

public void show()

{

System.out.println(“X=”+x);

}

}

 

class Testing

{

public static void main(String args[])

{

Public object=new Public();

object.show();//Accessible from anywhere

}

}

 

—————————

class PrivateExample

{

private int x=100;

 

private void display()

{

System.out.println(“X=”+x);

}

public void show()

{

display();

}

}

class Test

{

public static void main(String args[])

{

PrivateExample object=new Private Example();

object.show();//allowed

//object.display()//not allowed

//System.out.println(object.x);//not allowed(x private)

}

}

 

What are Access Modifiers in java

Leave a Reply

Your email address will not be published. Required fields are marked *

EduLearn - Online Education Platform

Welcome to EduLearn!

Start learning today with our wide range of courses taught by industry experts. Gain new skills, advance your career, or explore new interests.

Browse Courses

Popular Courses

[Course Image]

Introduction to Programming

Learn the fundamentals of programming with Python in this beginner-friendly course.

12 Hours Beginner
[Course Image]

Data Science Essentials

Master the basics of data analysis, visualization, and machine learning.

20 Hours Intermediate
[Course Image]

Web Development Bootcamp

Build modern websites with HTML, CSS, JavaScript and popular frameworks.

30 Hours Beginner
[Course Image]

Digital Marketing Fundamentals

Learn SEO, social media marketing, email campaigns and analytics.

15 Hours Beginner
Educational Website Footer