inheritance

How does polymorphism work for inner classes?

≯℡__Kan透↙ 提交于 2020-01-06 03:19:07
问题 When I tried to understand how to work with collections in java, I realised that I don't understand how polymorphism works for inner classes. Simple code example: class Parent { public static void main(String[] args) { new Parent().newInnerClass().myMethod(); new Child().newInnerClass().myMethod(); } public I newInnerClass() { return new InnerClass(); } private final class InnerClass implements I { @Override public void myMethod() { System.out.println("parent inner class"); foo(); } } public

Writing an equals() method for Inheritance in Java

倖福魔咒の 提交于 2020-01-06 02:53:07
问题 Im doing an inheritance question and I have everything completed except the Boolean part. My code will compile, but when comparing the name, birthday, and ssn, it will only come out as false. For example, I inputted: Jim 6 30 2001 123456789 Jim 6 30 2001 123456789 The output will be false. public class Person { private String name; private Date birthday; private int ssn; public Person(String name, Date birthday, int ssn) { this.name = name; this.birthday = birthday; this.ssn = ssn; } public

Activity layout inheritance

梦想的初衷 提交于 2020-01-06 02:50:14
问题 I start develop application on Android! I need to show common control on the top of few screens. In Blackberry I just inherit my screens from base screen with needed controls and it inherit UI and behaviour from base type. How can i do similar thing in Android? I mean, how can i organize it? Maybe, i need to create control or layout, which i can use on my screens? Or i need inherit one activity from another and use addContentView()? What opportunities are there and what advantages /

How to hide the entire class?

喜夏-厌秋 提交于 2020-01-06 02:41:10
问题 Lets imagine: // assembly 01 abstract class Foo { abstract void Bar(); } class AdvancedFoo : Foo { override void Bar() { base.Foo(); ... } } sealed class SuperiorFoo : AdvancedFoo { override sealed void Bar() { base.Foo(); } } And then I want to reference that assembly 01 from my 02 asm and replace the intermediate base class (and only it) so the instances of a SuperiorFoo were acting like they are inhereting from assembly 02 's AdvancedFoo . // assembly 02 class AdvancedFoo : Foo { override

template inheritance and member access

╄→гoц情女王★ 提交于 2020-01-06 02:14:58
问题 I have the following simple code: template <typename T> struct base { std::vector<T> x; }; template <typename T> struct derived : base<T> { void print() { using base<T>::x; // error: base<T> is not a namespace std::cout << x << std::endl; } }; When I compile the code (using GCC-4.7.2) I get the error that you see in the comment above. I read here: http://gcc.gnu.org/onlinedocs/gcc-4.7.2/gcc/Name-lookup.html#Name-lookup that using base<T>::x has to be included in order to bring in the scope of

Storing list of generic class of derived objects

纵饮孤独 提交于 2020-01-06 01:36:50
问题 For example, how do I store a list of DataContainers that all use types that derive from the same base class. public class Animal {} public class Cat : Animal {} public class Dog : Animal {} public class DataContainer <TData> where TData : Animal { TData innerObject = new TData (); public TData GetData () { return innerObject; } } public class DataManager { static void Main () { DataContainer<Cat> CatData = new DataContainer<Cat> (); DataContainer<Dog> DogData = new DataContainer<Dog> (); var

Typical Hierarchical inheritance in Java

放肆的年华 提交于 2020-01-05 17:57:06
问题 Consider this below code snippet public class SuperClass { public void move() { System.out.println("i am in super class"); } } public class SubClass1 extends SuperClass{ public void move() { System.out.println("i am in sub1 class"); } } public class SubClass2 extends SuperClass { public void move() { System.out.println("i am in sub2 class"); } } Now i am creating object like this. public class program { public static void main(String[] args) { SubClass1 obj = new SubClass2(); // Compile error

Django: store common fields in a parent model

梦想与她 提交于 2020-01-05 14:07:34
问题 I've got some models: class Place(models.Model): name = models.CharField(unique=True) class Bar(Place): drinks = models.ManyToManyField('Drink') class Restaurant(Place): meals = models.ManyToManyField('Meals') That's a multi-table inherited structure where each bar serves drinks only, and each restaurant serves meals only. I, though, need a name of each place to be unique across all the places - hence the parent Place model. Now, multi-table inheritance presumes a parent and a child are

Should Player inherit or own a Level?

 ̄綄美尐妖づ 提交于 2020-01-05 10:32:11
问题 I've been trying to learn OOP for the last few weeks as much as I can, and I've learned alot, but I'm not certain of this one, what should my class hierarchy look like? Imagine two classes, here's a Level -class: class Level(object): def __init__(self, level, exp): self.level = level self.exp = exp @property def required_exp(self, level=None): return 80 + 40 * (level or self.level) def add_exp(self, exp): self.exp += exp while self.exp >= self.required_exp: self.exp -= self.required_exp self

How to inherit GORM mapping from non domain class?

假如想象 提交于 2020-01-05 10:32:09
问题 Permanently I have some tables and some hibernate classes with mapping annotations. And this classes have abstract superclass with mapping annotations also. But in this superclass there is no table association mapping. All tables are identified in the subclasses. I'm trying to migrate this mapping to GORM model. But all strategies: TablePerHierarchy and TablePerSubclass not approach for my case because all tables is created and can't be changed. I created superclass in the 'src/groovy