Questions tagged [superclass]

A superclass is a parent or base class that is derived or inherited from by a child class (or subclass). Superclasses are used extensively in object-oriented programming (OOP).

SuperClass

A superclass is a class that has been extended by another class. It allows the extending class to inherit its state and behaviors.

Example

In this example, polygon is a superclass of triangle and rectangle:

enter image description here

Reference

1474 questions
13
votes
5 answers

Java: Force subclasses to override methods of the Superclass

How can I write a method and force the subclasses to override this method. In Eclipse it should show in the Quick-Fix Dialog: "Add unimplemented methods". Thanks
Dj Boris
  • 189
  • 1
  • 2
  • 10
13
votes
2 answers

Maximum recursion depth error in Python when calling super's init.

I have a class hierarchy A <- B <- C, in B, I need some processing in the constructor, so I came up with this code from this post: Understanding Python super() with __init__() methods #!/usr/bin/python class A(object): def __init__(self, v,…
prosseek
  • 182,215
  • 215
  • 566
  • 871
13
votes
4 answers

Calling superclass from a subclass constructor in Java

I am trying to create a constructor that takes a field as a parameter, then puts it in a field that is stored in a superclass. Here is the code I am using public crisps(String flavour, int quantity) { this.flavour = super.getFlavour(); …
user215732
  • 153
  • 1
  • 3
  • 10
12
votes
2 answers

dynamic class inheritance using super

I'm trying to dynamically create a class using type() and assign an __init__ constructor which calls super().__init__(...); however, when super() gets called I receive the following error: TypeError: super(type, obj): obj must be an instance or…
sadmicrowave
  • 39,964
  • 34
  • 108
  • 180
12
votes
10 answers

Why HashMap with generic declaration " does not accept value "new Object()" in the put method?

While working on interview questions, I have come across below code: List list = new ArrayList(); Map m = new HashMap(); m.put(1, new Object()); m.put(2, list); The above two put method's are…
MKod
  • 803
  • 5
  • 20
  • 33
12
votes
3 answers

super keyword without extends to the super class

There is a code of simple program. In constructor, super() is called without extends to the super class, I can not understand what will does this in this situation? public class Student { private String name; private int rollNum; …
Roledenez
  • 751
  • 4
  • 16
  • 43
11
votes
6 answers

Call subclass's method from its superclass

I have two classes, named Parent and Child, as below. Parent is the superclass of Child I can call a method of the superclass from its subclass by using the keyword super. Is it possible to call a method of subclass from its…
Confused
  • 3,846
  • 7
  • 45
  • 72
11
votes
5 answers

method must call super() error in Netbeans

Recently I've made a Netbeans project and I am using SVN along with it. I am seeing duplicate class error, and in the console it says java.lang.VerifyError: (class: pie/chart/explorer/PieChartExplorer, method: signature: ()V) Constructor must…
Andrew delgadillo
  • 714
  • 6
  • 13
  • 24
11
votes
2 answers

Call method from another method in abstract class with same name in real class

I have an abstract class and one class that extend it, I have a method with same name in both class. I want to call the method in abstract class in another method of abstract class. Controller.java public abstract class Controller { public…
Mohse Taheri
  • 741
  • 1
  • 6
  • 23
10
votes
3 answers

Can I mock a superclass's constructor with Mockito/Powermock?

Is it possible using Mockito and optionally Powermock to mock a superclass S such that any calls to the superclass to S (including calls to the S() constructor) are mocked? So using the below example, if I replace S with MockS using Mockito, will…
Jeff Axelrod
  • 27,676
  • 31
  • 147
  • 246
10
votes
1 answer

Calling parent's __call__ method within class

I'd like to call a parent's call method from inherited class Code looks like this #!/usr/bin/env python class Parent(object): def __call__(self, name): print "hello world, ", name class Person(Parent): def __call__(self,…
Jan Vorcak
  • 19,261
  • 14
  • 54
  • 90
10
votes
5 answers

General 'map' function for Scala tuples?

I would like to map the elements of a Scala tuple (or triple, ...) using a single function returning type R. The result should be a tuple (or triple, ...) with elements of type R. OK, if the elements of the tuple are from the same type, the mapping…
Stefan Endrullis
  • 4,150
  • 2
  • 32
  • 45
10
votes
3 answers

Java Web Services/JAXB - Abstract superclass

I have a package with JAXB annotated classes with an abstract superclass. I want to use this superclass in web service interface, so I can pass any of subclasses as a parameter. When I do it, an exception is thrown: javax.xml.ws.WebServiceException:…
alex.zherdev
  • 23,914
  • 8
  • 62
  • 56
10
votes
7 answers

Calling super() with no Superclass?

What happens (if anything) when a constructor calls 'super()' without having any superclass besides Object? Like so: public class foo implements Serializable, Comparable { int[] startPoint; public foo() { super(); startPoint =…
Yozarian22
  • 279
  • 4
  • 9
10
votes
4 answers

What is the best practice for finding all the superclasses of a Perl class?

Is there a standard CPAN way of finding out all the superclasses of a Perl class (or better yet entire superclass tree, up to UNIVERSAL)? Or is the best practice to simply examine @{"${$class}::ISA"} for each class, class's parents etc?
DVK
  • 126,886
  • 32
  • 213
  • 327