Skip to main content

Questions tagged [access-modifiers]

Access modifier is an OOP concept. It determines what level of access or visibility a particular property/method/class has.

access-modifiers
0 votes
1 answer
42 views

Change in object properties after change in access modifier

In my Student class, the variable is first set to: public String name; I access this in the other class named StudentUse class as follows: Student s1 = new Student(); s1.name= "sarang"; ...
Sarang Tripathi's user avatar
-1 votes
1 answer
41 views

Java Protected Field Access Issue in Subclass

What is the difference between public, protected, package-private and private in Java? The question's answer cannot answer my question. It's not a duplicate question. I totally know the diagram of ...
maplemaple's user avatar
  • 1,435
0 votes
0 answers
38 views

Refactor multiple public classes in a folder/namespace to internal classes

Imagine 10 public classes in a folder/namespace. I want to make all of them internal. Any way to do this using Rider without modifying each file manually?
me.at.coding's user avatar
  • 16.6k
4 votes
3 answers
95 views

Why can't I access the public method after overriding a protected method?

I have a question about access modifiers override. First, let's look at the following code. fun main() { val b: AAA = BBB() b.testA() } open class AAA { fun testA() { println(&...
ybybyb's user avatar
  • 1,667
3 votes
5 answers
125 views

How to propagate the value of an init-only property to an enclosed class?

I have a Wheel class with two init-only properties Spokes and DiskBrake: public class Wheel { internal Wheel() { } public int Spokes { get; init; } public bool DiskBrake { get; init; } } ...
Theodor Zoulias's user avatar
0 votes
0 answers
114 views

How to make ruff understand an attribute as "protected" in python?

I am trying to use something similar to a protected attribute in python and I am using ruff as a linter. Of course I know that python is not a langage which supports access protection but ruff has a ...
Paulo-99's user avatar
2 votes
0 answers
70 views

How to detect classes marked with file modifier in C#

In C# 11, the new file type modifier was introduced. I was looking for a way to detect such non-public type using reflection, however, I have not find any "good" way to do so. There is no Is…...
Matt Stuvysant's user avatar
0 votes
2 answers
107 views

Why can't I declare a private member of a file-local type in another class within the same file?

This code: public class Class1 { private Class2 _class2; private void Something() { Class2 class2; } } file class Class2 { } produces compiler error CS9051 on the member ...
rory.ap's user avatar
  • 34.8k
1 vote
1 answer
89 views

Scala case class: Is public var member possible?

Scala noob here, but while learning about case classes, I see the members are by default read-only. However, if you add var, they become private; and there is no public access modifier. Any way to ...
mishar's user avatar
  • 455
4 votes
3 answers
242 views

Python access modifiers as a decorator

Is it possible to implement protected and private access modifiers for classes with decorators in python? How? The functionality should be like the code below: class A: def public_func(self): ...
Ehsan's user avatar
  • 147
0 votes
0 answers
68 views

Why is overriding necessary for the clone() method in the class if we are calling the clone() on the instance of the class in some other class? [duplicate]

class Cat { int j; Cat(int j) { this.j = j; } } class Dog implements Cloneable { int i; Cat c; Dog(Cat c, int i) { this.c = c; this.i = i; } ...
Mayor23's user avatar
0 votes
0 answers
150 views

What does a readonly modifier for a method do?

I write this code struct Test { public override string ToString() => "some text"; } Then I get a compiler message suggestion IDE0251 Member can be made 'readonly' this ...
Pawulon's user avatar
  • 67
0 votes
0 answers
18 views

Why can't public access modifier be used only in explicit interface implementation? [duplicate]

While studying C# from a book, I encountered some parts of the sample code that I couldn't comprehend. In C#, if a class inherits from an interface and implicitly implements the interface, the class's ...
Lil Manta's user avatar
0 votes
2 answers
176 views

Can I make internal enum visible to the test project, and use it in public test method?

I have internal enum MyEnum in the project. And I also have a custom attribute on some of the values of MyEnum, like: internal enum MyEnum { [CustomAttribute("value")] EnumValue, } ...
mati's user avatar
  • 76
-3 votes
1 answer
45 views

Problems with "Access Modifiers" in a class

I can't use any types of "Access Modifiers" in may "Class". If i try to use for example "Public" or "Internal" it comes with fail-code's "CS1519" &...
seb med hh Seb med hh's user avatar

15 30 50 per page
1
2 3 4 5
71