Questions tagged [protected]

`protected` is an access specifier in object-oriented languages. When the members of a class are `protected`, there is restricted access to these members for other classes.

The protected keyword specifies access to class members in the member-list up to the next access specifier (public or private) or the end of the class definition. Class members declared as protected can be used only by the following:

  • Member functions of the class that originally declared these members.
  • Friends of the class that originally declared these members.
  • Classes derived with public or protected access from the class that originally declared these members.
  • Direct privately derived classes that also have private access to protected members.
  • In the Java language, classes in the same package as the class that originally declared these members.
1204 questions
-1
votes
3 answers

Protection level of method to use with generics

My generic class is defined as follows: public class MySortedList where TItem : MyClass In one of class' methods I create an instance of TItem and call one of its protected methods: TItemInstance.MyMethod(); Here I get the…
Yevgeni Grinberg
  • 359
  • 5
  • 19
-1
votes
1 answer

Access to Protected from other package in Java

Why i cant call protectedMethod() even the object of class Parent call its method? package packageA; public class Parent{ protected void protectedMethod(){ System.out.println("Hello Parent"); } } and in another Package : package…
-1
votes
1 answer

C++ Class Constructor defined public, says it's protected

I have a project going with multiple levels of inheritance. It goes like this XMLs -> Entity -> Item and then there are numerous item classes that inherit from Item which then inherit from Entity. Now, I have each class defined as shown class…
zburns12
  • 1,783
  • 3
  • 15
  • 16
-1
votes
1 answer

I want to use in oop with protected static

I am learning oop. I try to cover the oop and to understand the idea behind oop. I have code and i want to use with protect static for an understanding. I Declare attributes: protected static $formula . And I call to protected static $formula by…
israel love php
  • 457
  • 3
  • 6
  • 17
-2
votes
0 answers

reverse proxy for minecraft server

im currently trying to make it where my minecraft server has a reverse proxy that mostly shields it against ddos attacks and recently i have found a proxy i can host on my computer called proxy.py im getting help from chat gpt to make the proxy as…
poop face
  • 1
  • 3
-2
votes
1 answer

Protected variable not accessible within child class in Java

I have the following structure - App.java - package JohnParcellJavaBasics.AccessModifierDemo; import JohnParcellJavaBasics.AccessModifierDemo.*; public class App { public static void main(String[] args) { } } AnimalApp.java…
Payel Senapati
  • 1,134
  • 1
  • 11
  • 27
-2
votes
1 answer

Itext7 moving public method to protected

I'm migrating from itext v5 to v7 and found the PdfSignatureAppearance class has changed its method setSignDate() from public to protected. I can't find the reason why is it necessary? (I know that protected method can only be used in inherited…
nil96
  • 313
  • 1
  • 3
  • 12
-2
votes
1 answer

Not able to access base protected members in derived class ! ( in virtual functions )

I have a abstract class e.g. A ( few pure virtual functions ). I am public inheriting class B from class A. While providing the definitions of virtual functions, I am trying to access the private members of class A (e.g. Ptr ). However, compiler…
-2
votes
1 answer

C2248 - From to 2 inheritances

I have 3 classes, 1 inherited by another. A->B->C. A has a protected member function that I'm trying to set using C. I'm getting C2248 - Error C2248 'A::status': cannot access inaccessible member declared in class 'A' Associations Am…
S. Gu
  • 1
-2
votes
1 answer

Python class inheritance to c++

Before doing a C++ class, I decided to first do it in Python. There were good sources to do the Python class but I couldn't find useful sources for C++. Python code: class Human: def __init__(self, first, last, age, sex): self.firstname…
Miguel Yurivilca
  • 375
  • 5
  • 12
-2
votes
2 answers

Variable is protected when using friend function

I've had to make a program which shows the name, surname and the year of birth of a child. Everything is working well, excepting the friend function, which have to access the private/protected variable birth_year and to show 0 if his birth_year is…
system32
  • 15
  • 5
-2
votes
2 answers

Why does calling a method from base class calls the child method?

I'm a student, learning Java. I know, protected means access from children or the same package. Here we inherit and override a protected method. And after such an action, whenever the base class wants to call its own method it calls the new…
Sam
  • 1,832
  • 19
  • 35
-2
votes
2 answers

Can't access protected int variable of the pointer Parent class

I have a question about protected variables. Maybe i didn't really understand them but isnt the reason to use them, that child classes can use them? Overall i want to decrease the lifepoints. Here is my code: Header file class Fighter { protected: …
David Walser
  • 183
  • 20
-2
votes
3 answers

In Java, can a class access the protected attribute in the super class of its super class?

For example, public class Question { protected String question, correctAnswer, type; .... } public class MultipleChoice extends Question{{ ... } public class TrueFalse extends MultipleChoice{ public TrueFalse(){ this.type = "TrueFalse"; …
Allen Yang
  • 81
  • 2
  • 10
-2
votes
2 answers

how to protect download link using html and javascript?

i have two download links. after right click on this link it showing option link "open in new tab" "save link as" "copy link location" and so on. but i want to protect this link. there should not showing this option when right click on download…
Neeya
  • 135
  • 8