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
-3
votes
1 answer

What components of the superclass do the subclasses inherit?

Do all of the subclasses of a superclass inherit the superclass' instance variables, constructors, mutators, and accessors? Assuming that all members of the superclass is public.
Proxy
  • 3
  • 1
-3
votes
1 answer

Why is the superclasses field different when called from subclass?

Why is field nodes returning different size when called from subclass shouldn't subclasses have access to their super classes fields? Here is reproducible example: Manager.java import java.util.HashMap; public class Manager { protected…
Borel
  • 29
  • 4
-3
votes
2 answers

Does python have super().__init__().area() this kind of method?

class Square(): def __init__(self,side): self.side = side def area(self): return self.side * self.side class cube(Square): def area(self): return super().__init__().area() * 6 def volume(self): …
-3
votes
1 answer

I created a subclass of the Rectangle class, but I'm only able to return the superclass' default values of x and y

I'm working on a school project where I need to extend Java's default Rectangle class into a subclass called MyRectangle; the subclass has additional variables including width and height, and when I use a dot operator to print those values out I get…
-3
votes
1 answer

ruby - One superclass , 2 subclasses and One common Method - Having an error

The following has Universe(superclass) , Common(module), FlatEarthBelievers(subclass) and RoundEarthBelievers(subclass). There is an error with the output and want to make it work, any pointers? This is about inheritance and mixins, a scenario…
-3
votes
2 answers

What's the reason behind this access restriction for superclass and subclass?

I'm trying to understand the rationale for the last statement of my code being illegal in Java. See comment below. public class Rectangle { private int height; private int width; public Rectangle(int height, int width) { this.height =…
yinder
  • 17
  • 1
  • 7
-3
votes
1 answer

Accessing superclass method of subclass through another class in java

What is the best solution for this problem? This is the superClass public class Views { private T controller; public Views() { } public Stage getStage(Node object){ return (Stage) object.getScene().getWindow(); } public T…
Hugo Modesto
  • 63
  • 1
  • 8
-3
votes
2 answers

Multilevel inheritance in java

Suppose if a class A is superclass of sub class B and class B is a superclass for sub class C then which of the following statements should be used? And tell whether the statement not chosen is 'wrong' or is there any other reason? Statement 1: sub…
Himanshu Roy
  • 43
  • 2
  • 11
-3
votes
1 answer

Are there any potential issues with setting super() to a class attribute?

I've slightly changed the way I use super as I've got a little more familiar with it, and each time I've found an issue. I'm still having to use Python 2.7 so the old syntax is necessary. Two of the alternate ways I've tried and stopped using are…
Peter
  • 3,186
  • 3
  • 26
  • 59
-3
votes
2 answers

Can only make one extended class in java, the other ones have to be in own file apparently

I have been trying to make three different extended classes from a superclass. The problem is that only the first extended class works fine while the other two gets an error when I name them, and its says they should be in their own file. I have…
mackanmorre
  • 145
  • 1
  • 13
-3
votes
1 answer

How to initialise method of superclass in constructor of subclass

SuperClass public class Kola { int id; Put put = new Put(id, id); public Kola(int id1) { id1=0; } public int prelazenje(int p){ return p = (int)(5 + (Math.random() * (10 - 5))); } public int paljenje (int pa){ …
-3
votes
2 answers

Call to super must be first statement in constructor?

public class Gonderi { int kullaniciId; int gonderiId; public void Gonderi(int kullaniciId, int gonderiId) { …
Taha Sümer
  • 25
  • 11
-3
votes
2 answers

JAVA Inheritance student, undergrad and gradstudent code

For a class project I was asked to create three codes. Student Class First, the student class containing three Parameters. Name(String) TestScores( int array), Grade(String). An empty Constructor. sets the Name and Grade to empty Strings. The…
vmjiron
  • 13
  • 1
  • 4
-3
votes
1 answer

Accessing instance of a package-private subclass as its public superclass

I'm writing a multiplayer game engine where I've mapped the traditional MVC pattern into Game/Client/Server (Game is the "model" that the other parts act on and communicate through. Client has its own MVC structure internally.) I'm doing my best to…
and0
  • 3
  • 1
-3
votes
2 answers

Inheritance missing attribute

I get an error saying that the class Guitar doesn't have attribute "type", but it should inherit from super class Equipment. class Equipment(object): __id = 0 __type = 0 __brand = 0 __model = 0 __serialNumber = 0 …