Skip to main content

All Questions

Tagged with
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 ...
1 vote
1 answer
309 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
742 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 ...
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() ...
-2 votes
1 answer
504 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
416 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) { ...
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(){ }...
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
213 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
718 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 ...
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 ...
0 votes
1 answer
375 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
535 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 ...

15 30 50 per page
1
2 3 4 5