All Questions
Tagged with visibility inheritance
64
questions
1
vote
1
answer
299
views
Do inherited methods use the visibility, methods and attributes of the superclass or subclass?
What I assume is that an inherited method will, by standard, use the methods and attributes of the class whose object is used to execute that method.
Here's an example for my question, it's from a ...
0
votes
1
answer
729
views
why can't I access a protected method from a private method if the protected ones are inherited by the subclasses?
I do not understand this particular case or what Alexander says.
class instance is not the same as class?
As already Alexander Larikov said that you can't access protected
methods from class instance ...
-2
votes
1
answer
501
views
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[]...
-1
votes
3
answers
415
views
Java Overridden method visibility scope
How is the following program correct?
abstract class Calculate
{
abstract int multiply(int a, int b);
}
public class Main
{
public static void main(String[] args)
{
...
1
vote
0
answers
39
views
Why below code gives error even if the public function in derived class is the one being called..?
In the following code a public function has overriden a private virtual function in base class
ob->hello() shall call hello() in derived class which is public.
why do i still see an error that ...
0
votes
1
answer
212
views
Is it possible to encapsulate open and override variables to prevent direct access from main() function while implementing inheritance in Kotlin?
My code -
fun main() {
val student = Student()
student.greet()
}
open class Person(open var name: String) {
fun greet() {
println("Hello $name")
}
}
class Student(...
2
votes
2
answers
713
views
PHP: understanding $this - calling base class method instead of child method
Reading the PHP.net documentation I stumbled upon a problem that twisted the way I understand $this:
class C {
public function speak_child() {
//echo get_class($this);//D
echo $...
1
vote
1
answer
146
views
Inheritance in C: how to hide "super class" attributes to the class extending it
As a learning experience I'm trying to achieve simple class inheritence in C, among other OOP features.
So far I've been able to properly hide "private" functions and attributes of a class from the ...
0
votes
1
answer
373
views
protected method vs protected property
Subclasses need to be able to use the seeded random number generator.
What are the pros and cons of using
public abstract class AbstractClass {
protected Random rnd;
public AbstractClass(long ...
0
votes
1
answer
533
views
Parent's protected properties inaccessible to child object
I have a parent class I'll be calling 'ParentClass' and a child class (that extends from it) which I'll be calling 'ChildClass'.
ParentClass has protected properties $prop1 and $prop2 which I want ...
0
votes
0
answers
38
views
How to make available only those public methods which are declared in interface?
In Java, for example, this comes out of the box due to static nature of the language. But in PHP this could be also useful especially to keep a code secure and clean from an architectural point of ...
0
votes
1
answer
61
views
Package-private member visibility in complex inheritance / package combinations - Qiuck General Rule to verify visibility
If Base and Derived classes are in different packages then package-private member from Base shall not be inherited and thus it shall be absent in Derived, that is such member shall be inaccessible ...
0
votes
1
answer
263
views
C++ - Accessibility VS visibility
I am working on an exercise to make sense of C++'s accessibility VS visibility.
The following code doesn't compile obviously, but this is what it ideally must be.
B inherits from A with template ...
0
votes
1
answer
499
views
Java method that can't be callable but can be overridden
If I don't want that a method on my class can be called, I just make it private.
But if I want to allow that method to be overridden, I have to make it protected
Is it possible to have a method on ...
8
votes
2
answers
12k
views
Swift 3 access of private properties in a struct from a extension
I've been looking through the swift docs and working through some examples around encapsulation, and am unsure about the behaviour that I'm seeing. I've looked for similar questions on stack, looked ...