Questions tagged [subclass]

A subclass is a class that derives or inherits from a parent (or super) class. Subclassing is used extensively in object-oriented programming (OOP).

A subclass is any class that inherits from a parent (or super/base) class. Depending on the language, a subclass will have a subset of the attributes and methods of the (parent/base) class from which it inherits. As a result, it is important to always tag a question with the language being used when tagging it with this tag

4137 questions
20
votes
4 answers

When to use which Writer subclass in Java; common practices

I have always been slightly confused with the amount of different IO implementations in Java, and now that I am completely stuck in my project development, I was taking my time to read up on useful stuff meanwhile. I have realized that there is no…
posdef
  • 6,498
  • 11
  • 46
  • 94
20
votes
3 answers

Swift 3: subclassing NSObject or not?

I have read some posts like this one about the difference between subclassing NSObject in Swift or just having its native base class with no subclassing. But they all are a bit old posts, and I am not clear about this topic. When should you subclass…
AppsDev
  • 12,319
  • 23
  • 93
  • 186
20
votes
4 answers

Returning an objects subclass with generics

With an abstract class I want to define a method that returns "this" for the subclasses: public abstract class Foo { ... public T eat(String eatCake) { ... return this; } } public class CakeEater…
Sarabjot
  • 489
  • 1
  • 4
  • 13
20
votes
4 answers

Avoid specifying all arguments in a subclass

I have a class: class A(object): def __init__(self,a,b,c,d,e,f,g,...........,x,y,z) #do some init stuff And I have a subclass which needs one extra arg (the last W) class B(A): def __init__(self.a,b,c,d,e,f,g,...........,x,y,z,W) …
olamundo
  • 23,991
  • 34
  • 108
  • 149
20
votes
8 answers

Why subclass in another package cannot access a protected method?

I have two classes in two different packages: package package1; public class Class1 { public void tryMePublic() { } protected void tryMeProtected() { } } package package2; import package1.Class1; public class Class2 extends…
user2986848
  • 217
  • 1
  • 2
  • 3
20
votes
11 answers

Class extending more than one class Java?

I know that a class can implement more than one interface, but is it possible to extend more than one class? For example I want my class to extend both TransformGroup and a class I created. Is this possible in Java? Both statements class X extends…
Mihai Bujanca
  • 4,089
  • 10
  • 43
  • 84
19
votes
3 answers

SPARQL: Get all the entities of subclasses of a certain class

I've to get all the instances of a class C and subclasses (direct or indirect) of C, in SPARQL. I can get all the direct subclasses of C in this way: SELECT ?entity WHERE { ?subclass rdfs:subClassOf :C . ?entity rdf:type ?subclass . } But I…
auino
  • 1,644
  • 5
  • 23
  • 43
19
votes
6 answers

Implemented classes / subclasses in content assist in eclipse

What I'm trying to do is this: List list = new and then hit Ctrl+Space and get ArrayList() (among others) to show up in the type proposal. I thought I had this working previously, but I recently had to reinstall and can't find the…
Kevin McCarpenter
  • 786
  • 1
  • 7
  • 22
19
votes
3 answers

Get overridden functions of subclass

Is there a way to get all overriden functions of a subclass in Python? Example: class A: def a1(self): pass def a2(self): pass class B(A): def a2(self): pass def b1(self): pass Here, I would like…
18
votes
9 answers

Is it possible to call subclasses' methods on a superclass object?

Animal is a superclass of Dog and Dog has a method called bark public void bark() { System.out.println("woof"); } Consider the following: Animal a = new Dog(); if (a instanceof Dog){ a.bark(); } What will happen? the assignment isn't…
roberto
18
votes
9 answers

What is the correct (or best) way to subclass the Python set class, adding a new instance variable?

I'm implementing an object that is almost identical to a set, but requires an extra instance variable, so I am subclassing the built-in set object. What is the best way to make sure that the value of this variable is copied when one of my objects is…
rog
  • 6,252
  • 4
  • 31
  • 25
18
votes
5 answers

Private members in Java inheritance

I was told that for a Java subclass it can inherit all members of its superclass. So does this mean even private members? I know it can inherit protected members. Can someone explain this to me. I am now totally confused.
Mandy M
  • 215
  • 1
  • 3
  • 5
18
votes
2 answers

How to initialize an NSObject's subclass on iPhone?

I want to write some methods in a class so that other classes can call these methods using [instance methodName:Parameter]. If the class is a subclass of UIViewController, I can use initWithNibName to initialize it. But I want to write the methods…
Chilly Zhong
  • 16,763
  • 23
  • 77
  • 103
18
votes
3 answers

how to obtain all subclasses of a class in php

Is it possible to get all subclasses of given class in php?
liysd
  • 4,413
  • 13
  • 35
  • 38
18
votes
7 answers

The type name {myUserControl} does not exist in the type {myNamespace.myNamespace}

I have a problem (obviously the question :) I have a project-- MyProject... hence the rest of the project uses a default of any classes as namespace "MyProject"... no problem. In my project, I created a custom user control that has many other…
DRapp
  • 47,638
  • 12
  • 72
  • 142