0% found this document useful (0 votes)
8 views1 page

Python vs Java Access Modifiers Guide

Uploaded by

chennujaswanth7
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views1 page

Python vs Java Access Modifiers Guide

Uploaded by

chennujaswanth7
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Access Modifiers: Python vs Java Comparison

Side-by-Side Comparison Table

Feature Java Python

Public `public` keyword


No underscore (e.g., `name`)

Protected `protected`
Single
keyword
underscore (e.g., `_name`)

Private `private` keyword


Double underscore (e.g., `__name`)

Enforced by Compiler? Yes No (uses convention)

Accessible in Subclass Yes (protected/public)


Yes for `_var`, No for `__var`

Outside Class Access `public/protected`


`_var` possible,
allowed`__var` via mangling

Code Examples

Java:
public class Student { Python:
public String name = "Ram"; class Student:
protected int age = 20; def __init__(self):
private double gpa = 8.9; [Link] = "Ram" # public
} self._age = 20 # protected
self.__gpa = 8.9 # private

You might also like