superclass

Java: Can a class inherit from two super classes at the same time?

主宰稳场 提交于 2019-12-10 10:16:24
问题 I have a class Journey which I want to make a superclass and another class plannedjourney. The plannedjourney class extends JFrame since it contains forms..However I also want this class to extends Journey.. Is there a possible way to do this? 回答1: Don't mix models and views. If you keep both domains clearly separated, then you won't be in need of multiple inheritance (this time). You have one model class for journeys and a viewer for such journeys. The viewer should subclass Component and be

Interfacing with super and subclass constructors

白昼怎懂夜的黑 提交于 2019-12-09 18:36:01
问题 I have had trouble finding help in the matlab documentation and previous questions about using matlab inheritance and class constructors to make an interface. To make it tidy, within a package. Instead of dragging through my code I can condense it as follows: A package +MyPkg has a superclass Super and a few subclasses Sub1 Sub2 ... Most of my properties and methods are defined in Super such that Sub1 and Sub2 really only exist to use their constructors for simple routines or perhaps a few

Changing the value of superclass instance variables from a subclass

泪湿孤枕 提交于 2019-12-09 17:01:05
问题 I've found that I can do it this way in the child class: ParentClass.variable = value; But I've been told that it's better practice to use get/set methods and not give direct access to variables outside a class. Though this was for when I had an instance of the class in another class, not for subclasses and superclasses. So is there a better way of doing this, and which way is generally considered best practice? 回答1: You have a lot of options. super.field = x You have to have access to the

ANTLR @header, @parser, superClass option and basic file io (Java)

喜你入骨 提交于 2019-12-08 19:46:26
问题 I want to use parser actions with basic file io (Java), e. g. PrintWriter in an ANTLR grammar. Must I use the superClass option or can I use @header? In both cases how can I declare the PrintWriter-object and how must I handle the exceptions? 回答1: The option superClass=... is used to let your Parser extend a custom class. So, I don't think that is what you're after. Everything inside the @header section will be placed at the start of your Parser class. This is used to import classes: @header

Java: Getting the subclass from a superclass list

老子叫甜甜 提交于 2019-12-08 19:37:53
问题 i'm new with java and have 2 questions about the following code: class Animal { } class Dog extends Animal { } class Cat extends Animal { } class Rat extends Animal { } class Main { List<Animal> animals = new ArrayList<Animal>(); public void main(String[] args) { animals.add(new Dog()); animals.add(new Rat()); animals.add(new Dog()); animals.add(new Cat()); animals.add(new Rat()); animals.add(new Cat()); List<Animal> cats = getCertainAnimals( /*some parameter specifying that i want only the

How super is implemented in Java?

自古美人都是妖i 提交于 2019-12-08 16:45:39
问题 Where the "super" is actually defined? [When we're using super.someMethod()]. Is it defined as a field in java.lang.Object class or java.lang.Class class? When we're calling from a subclass, super contains the reference to it's superclass.In the same manner the super in superclass itself has reference to it's superclass [In this way upto java.lang.Object]. So, how java injects the superclass references to the "super" field which enables us to call superclass methods ? Is there any under the

JMockit mock protected method in superclass and still test method in real child class

放肆的年华 提交于 2019-12-08 10:20:25
问题 I am still learning JMockit and need help understanding it. I am testing a class that uses superclass methods. My test gets a null pointer when it attempts to use the superclass method due to code inside it that uses struts action context to get the session and pull an object from the session. The method I want to bypass the struts session stuff inside the protected method. public class MyExtendingClass extends MySuperClass{ public void methodIamTesting(){///} } public abstract class

Java: Superclass and subclass

匆匆过客 提交于 2019-12-08 03:55:04
问题 Can a subclass variable be cast to any of its superclasses? Can a superclass variable be assigned any subclass variable? Can a superclass be assigned any variable? If so, can an interface variable be assigned a variable from any implementing class? 回答1: Are all dogs also animals? Are all animals also dogs? If you need an animal, and I give you a dog, is that always acceptable? If you need a dog specifically, but I give you any animal, can that ever be problematic? If you need something you

TclOO Variable Scope with Inheritance/superclass

纵然是瞬间 提交于 2019-12-08 03:09:39
问题 I stumbled over the variable scope when inheriting a class with TclOO. The member variable nCrumbs below is not visible to the inherited class without repeating the declaration. Is there a way to avoid replicating all the variable declarations from the superclass? (I read through all the OO documentation, specifically oo::define and oo::object, also the non-exported stuff, googled for it. There are so many concepts to get around various things, I got lost. I am looking for something that

How & Why to use SUPER in code?

坚强是说给别人听的谎言 提交于 2019-12-07 22:43:06
问题 I work with some advanced JavaScript people and they have used the SUPER keyword in their code. I admit, I don't have a good grasp of how and why one can and would use this. Can someone direct me or show me how to become well versed in its usage and reasoning thereof? Here are some examples: openup: function( $super ) { $super(); this.shop.enable_access(); } addLeft: function( data ) { var cell = Element('td'); if ( data.item_data ) { var item = new SRIL(data.item_data); item.attach(cell);