Questions tagged [super]

super is a keyword or function used to access/invoke members and constructors of a superclass. Since different languages have such a feature, please use in combination with a language tag.

In Object Oriented programming, super is commonly used keyword to allow access to the members of the superclass from a derived class. It can also be used to select which superclass' constructor to execute when a subclass is created.

Although the concept is prevalent in many object oriented languages, every language has different usages for the keyword.

A few of the basic questions on super in different languages:

A superclass is also called base-class or parent-class and some languages use such keywords instead of super.

1757 questions
0
votes
1 answer

I can't get super() to work in python 2.7

With a simple pair of classes, I cannot get super working: class A(object): q = 'foo' class B(A): q = 'bar' def __init__(self): self.a = super(A, self).q a = B() errors like…
BFH
  • 99
  • 7
0
votes
0 answers

inner class inheritence using super keyword

class ClassA { class NestedA{}; } class class B extends ClassA.NestedA { B(ClassA instanceA) // non-default constructor { instanceA.super(); //1 }; } I read this code in a book but couldn't understand meaning of line marked 1. I haven't…
user2653926
  • 610
  • 7
  • 23
0
votes
1 answer

Using super in a subclass member in Python

Consider the following code: >>> class A: ... k = 1 ... >>> class B(A): ... k = super(B, cls).k ... Traceback (most recent call last): File "", line 1, in File "", line 2, in B1 NameError: name 'B' is not…
jazzblue
  • 2,411
  • 4
  • 38
  • 63
0
votes
4 answers

Returning from submethod from super

I have something like this: class SuperClass { public void onClick(){ if(disabled) return; } } class SubClass extends SuperClass { public void onClick(){ super.onClick(); System.out.println("Clicked"); } } This outputs…
usama8800
  • 893
  • 3
  • 10
  • 20
0
votes
2 answers

Super class method using subclass method

sorry for the question being ambiguous, but I found it hard to word the title right. I have a super class with a method called calculateTotal() and a method called toString(). I also have a sub class that overrides both method. The problem I'm…
Soy
  • 3
  • 1
0
votes
1 answer

Accessing a method in a super super class

I want to invoke a method on the parent of a parent class. I am almost certain this is possible, but the following produces an error: import javax.swing.undo._ def test(name: String): CompoundEdit = new CompoundEdit { override def…
0__
  • 66,707
  • 21
  • 171
  • 266
0
votes
1 answer

What is the difference between Super thing = new Sub() and Sub thing = new Sub()?

Super thing = new Sub(); Sub thing = new Sub(); What is the difference in terms of accessing thing and what I can do with it etc?
0
votes
1 answer

How can I stub out a call to super in a imported Java class in JRuby for testing

I am testing Java classes with RSpec and JRuby. How can I stub out a call to super in an imported Java class in my RSpec test? For example: I have 2 Java classes: public class A{ public String foo() { return "bar"; } } public class B…
Doug Chew
  • 1
  • 1
0
votes
0 answers

Passing values to super constructor to determine what modules to enable

I have an abstract class to be used as a template for my programs. This abstract class has a constructor that currently accepts 7 booleans, each defining whether or not a certain module will be used and should be enabled (constructed). Instead of…
CrypticStorm
  • 560
  • 2
  • 11
0
votes
4 answers

Java super and this keywords

I'm again here and I like to extend the question I made today about this and super keywords. Let's take some examples. Example 1 import java.applet.*; public class Main extends Applet { //overrides Applet.init () public void init…
L99
  • 44
  • 2
  • 5
0
votes
2 answers

How to use super() to inherit a particular class from multiple father classes?

My code is like this, and I want to use super() to inherit the features of Papa, how to do that? class Mama(object): def __init__(self): self.name = 'Mama' def feature(self): print "%s have big eyes" % self.name class…
Zen
  • 4,381
  • 5
  • 29
  • 56
0
votes
1 answer

error when attempt to use equals method

If two employee objects are the same, then I want to check if the same number is returned by the "getID()" method. I think I'm using the equals method wrong. I think something is wrong with the last line of code: I have to keep this code: public…
user2932
  • 137
  • 3
0
votes
1 answer

How to declare subclass constructor in java

I have an abstract class, Entity.java. I also have a class TransportUnit.java that extends the Entity class. Entities are to be constructed with a String name and int lifePoints. Transport Units are to be constructed with the same and in addition an…
j x
  • 317
  • 3
  • 12
0
votes
2 answers

Forcing base class functions to be used from the base class

The answer to this question is probably "W-what!? What the !@#$-- Stop!! That's a terrible idea!", but I would like to hear your thoughts... I have two classes and one inherits from the other. class A(object): def t1(self): self.t2() …
flakes
  • 21,558
  • 8
  • 41
  • 88
0
votes
1 answer

Is calling a superinterface's default method possible?

Say I have two classes, A and B: class A { void method() { System.out.println("a.method"); } } class B extends A { @Override void method() { System.out.println("b.method"); } } After instantiating B as…
The Guy with The Hat
  • 10,836
  • 8
  • 57
  • 75
1 2 3
99
100