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
0
votes
3 answers

Is there a way to declare a C++ protected variable from outside it's class?

class A { public: A(); int get(); void set(); }; protected int A::var; seems like it would work. However, it "expects an unqualified-id before protected". What's the correct way to do this?
Nathan Ringo
  • 973
  • 2
  • 10
  • 30
0
votes
2 answers

How to make private property accessible in MVC3

I'm using Mvc3 and NHibernate I have a class called Activation code like following: public virtual int LoginAccountId { get; set; } protected virtual string ActivatedCode { get; set; } protected virtual DateTime ActivationDate { get; set; } I want…
priya77
  • 175
  • 2
  • 10
  • 24
-1
votes
5 answers

protected access modifiers in .net

i created an application depicting the protected access modifiers, using the sample provided on MSDN site, but it seems to be error prone, below is the code i am using: and below is the sample from MSDN site:
Abbas
  • 4,948
  • 31
  • 95
  • 161
-1
votes
5 answers

in c#, is it possible to access the common protected fields of one child in another child class?

See the question in code: class commonParent { protected string name; } class child1:commonParent{ // do some stuff } class child2:commonParent{ // do some stuff protected void test(){ child1 myChild1 = new child1(); …
LazNiko
  • 2,083
  • 3
  • 25
  • 39
-1
votes
1 answer

OOP in PHP - Inheritance - protected method error

//((inheritance)) class ParentClass { public function public_message() { echo "This is a Public message" . "
" . "from Parent class ."; } protected function protected_message() { echo "This is a Protected…
-1
votes
2 answers

Why ant we have protected top level class in java?

If i have a top level class classA in packageA, and i want to make a classB extend classA, but i want to include classB in packageB, without any other class in packageB being able to have access to classA (so classA cannot be public), wouldnt this…
zenmonkey
  • 13
  • 2
-1
votes
1 answer

Google Apps Script Range Protection Lock Tab color and Tab Renaming

A spreadsheet with multiple tabs have 10 editors/access. I wanted to lock some ranges in each tab from 8 of those editors. When I ran google app script written below, it also lock the 8 editors from editing the tab name and even the tab color. Can…
-1
votes
1 answer

Multilevel protected Inheritance in C++

I'm having a scenario where i'm implementing multilevel inheritance but first level inheritance is specified as protected inheritance , but it is giving me compilation issue. class A { protected: int a1; }; class B: protected A { protected: …
amateur17
  • 9
  • 3
-1
votes
2 answers

Why ArrayList.removeRange() is not visible in the RoleList Class that extends ArrayList?

The method: protected void removeRange(int fromIndex,int toIndex) in class ArrayList is protected, so I cannot call it on an ArrayList object, but I can call it on an object from a class that extends ArrayList, as the code below shows. However, we…
blueSky
  • 649
  • 5
  • 13
  • 31
-1
votes
1 answer

Will a derived class call a protected constructor in base class before its own constructor?

My derived class should go through the same init procedure as the base class, initializing some vars and setting some states. The following is a simplified example: class Base { protected: int x = 0; Base() { x = 1; } …
glades
  • 3,778
  • 1
  • 12
  • 34
-1
votes
1 answer

Use of protected keyword in c#?

I want to understand the use of "protected" keyword in the following code (line 3). public class PlayerData { static protected PlayerData instance; static public PlayerData Instance { get { return instance; } } public int…
Achie1
  • 195
  • 2
  • 13
-1
votes
1 answer

Why does it get nothing that Getting private Properties? (c#)

public class A{ public Info m_Info = new Info(); Main() { Console.WriteLine(m_Info.Property_Count()); } public class Info{ protected int i_Id; protected string s_Name; public int…
-1
votes
1 answer

Protected issue with method in class

I have a Request_manager class with nested classes in it: class Request_manager { public: class Ticket { protected: explicit Ticket(System_time start_time); virtual void start() = 0; } …
Hector Esteban
  • 1,011
  • 1
  • 14
  • 29
-1
votes
2 answers

Protected method inheritance in C#

I have a simple C# code written after reading documentation about protected access modifier, but I am recieving a lot of illogical errors. I cant find any solutions to them. using System; public class WeaponController { protected void Reload() …
-1
votes
1 answer

Inheritance/Polymorphism - Am I forced to use "protected" variables?

I am currently working with Big C++ 2nd Edition, using Code::Blocks 17.12, on the chapter for inheritance The book introduces the protected variable type for cases in which you want to allow a derived class to access said variable. The book also…
Narish
  • 607
  • 4
  • 18