/* */ Click to Join Live Class with Shankar sir Call 9798158723

What is Protected Members Function in C++ ?


In the protected visibility mode, when we inherit a child class from the parent class, then all the members of the base class will become the protected members of the derived class.Protected members are declared with the keyword protected followed by the colon (:) character in the class and they are accessible within the class in which they are declared and also accessible in the derived or subclass. Protected members are used in the concept of inheritance.

Q.) Example of Protected Members Function in C++ .
    
 Class get
class Sample {
	protected int year = 2000;
	protected void printYear() {
		System.out.println("Its "+year+" !!");
	}
}

// Class put
public class Test {

	// Main driver method
	public static void main(String[] args) {
		Sample sample = new Sample();
		System.out.println(sample.year);
		sample.printYear();
	}
}

Output
2000
Its 2000 !!