Skip to main content

All Questions

Tagged with
43 votes
4 answers
212k views

Calling the base class constructor from the derived class constructor

I have a question: Say I have originally these classes which I can't change (let's say because they're taken from a library which I'm using): class Animal_ { public: Animal_(); int getIdA() ...
Joy's user avatar
  • 1,767
35 votes
7 answers
32k views

Expose a private Objective-C method or property to subclasses

According to some official talk, a class in Objective-C should only expose public methods and properties in its header: @interface MyClass : NSObject @property (nonatomic, strong) MyPublicObject *...
hzxu's user avatar
  • 5,813
25 votes
3 answers
21k views

Why can I override a protected method with public method?

The Java compiler doesn't complain when I override a protected method with a public method. What's really happening here? Is it overriding or hiding the parent method since the parent method has lower ...
Monstieur's user avatar
  • 8,092
18 votes
3 answers
3k views

Why can we reduce visibility of a property in extended class?

I have two classes, Parent: public class Parent { public String a = "asd"; public void method() { } } And Child: public class Child extends Parent{ private String a = "12"; ...
Bhuvan's user avatar
  • 4,148
14 votes
4 answers
9k views

Why does PHP allow protected and private methods to be made public via an override in subclasses?

From some brief fiddling about, I find I get an error when overriding superclass methods in a subclass when I do the following: Override a protected superclass method with a private subclass method ...
Matt Gibson's user avatar
  • 14.9k
10 votes
3 answers
12k views

PHP Inherited parent method can't access child's private property

First of all: A quite similar problem has been posted and somehow solved already, but is still not answering my specific problem. More about this later. In words: I have a base class which provides ...
Jan's user avatar
  • 103
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 ...
stevenpcurtis's user avatar
6 votes
4 answers
3k views

Policy inheritance and inaccessible protected members

It seems that a protected member from a template policy class is inaccessible, even with a class hierarchy which seems correct. For instance, with the following code snippet : #include <iostream&...
benlaug's user avatar
  • 2,741
6 votes
3 answers
5k views

How to prevent usage of public parent methods in child instance in PHP?

So let's say I have classes called parent and child, which will be then used from PHP file called caller.php class Child extends Parent { } class Parent { public function parentMethod(){ }...
Firze's user avatar
  • 4,019
6 votes
1 answer
670 views

Subclassing sun.* class in same package gives IllegalAccessError

Foreword: What am I going to show you is WRONG and I'm well aware of how bad I am for breaking encapsulation by doing such foolish thing. I'm not trying to solve any more general I/O problem. It's ...
woky's user avatar
  • 4,886
4 votes
1 answer
600 views

Destructor protection in abstract base class is not inherited in C++?

I found a memory leak in my code that was caused by calling only the base class destructor for objects. This problem is understood: I already added the virtual to the destructor of the interface class ...
Wolf's user avatar
  • 9,965
4 votes
2 answers
4k views

Only allow some classes to call a method in Java

Lets say I have a structure like this: Object A contains an instance of Object B Object B contains an instance of Object C Object D extends Object C I have an instance of object D that other ...
tgrosinger's user avatar
  • 2,539
3 votes
5 answers
7k views

Java Protected Access Not Working

In java, there's three levels of access: Public - Open to the world Private - Open only to the class Protected - Open only to the class and its subclasses (inheritance). So why does the java ...
Anton's user avatar
  • 1,427
3 votes
1 answer
128 views

Making an instance method inaccessible from a subclass

Given: class Base def foo puts 'foo!!!' end end class Ball < Base end I want: Ball.new.foo to return an error: No Method Found. Base.new.foo to return: foo!!!. My attempts are: I ...
Jay-Ar Polidario's user avatar
3 votes
1 answer
3k views

child class accessing parent's private method?

A user posted a comment on PHP Visibility manual page. It's the second most voted comment. He used this code example: <?php abstract class base { public function inherited() { $this-&...
Pontiac_CZ's user avatar

15 30 50 per page
1
2 3 4 5