overriding

Override AutoSize for derived Label Control in C#

微笑、不失礼 提交于 2019-12-31 06:28:56
问题 I am trying to extend the System.Windows.Forms.Label class to support vertically drawn text. I do this by creating a new property called MyLabelOrientation that the user can set to Horizontal or Vertical. When the user changes this setting, the values for width and height are swapped to resize the control to its new orientation. Finally, I override the OnPaint function to draw my Label. I would like to extend the AutoSize property for this control as well so that my Label will auto-size to

Class not serializable after methods are overridden

梦想的初衷 提交于 2019-12-31 02:44:04
问题 I override a createSocket() method in my test cases to pas in a mocked Socket. After doing this the objects aren't serializable anymore. Here's a example of what doesn't work. Foo.java import java.io.Serializable; public class Foo implements Serializable { private static final long serialVersionUID = 3109852436898487119L; public void bar() { System.out.println("Foo"); } } FooTest.java import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.ObjectOutputStream; import

How to override Show instance of some basic types in Haskell?

僤鯓⒐⒋嵵緔 提交于 2019-12-30 20:40:46
问题 I'm writting some programs in Haskell, dealing with a lot of basic types like Word32/Word64 etc.. I use ghci to test the functions frequently, see the results in terminal. To be convenient and fast, I always show data in hexadecimal e.g. data Human = M Int | F Int instance Show Human where show M x = printf "man, age %d" x show F x = printf "woman, age %d" x but I want basic types to be showed in hexadecimal (espacially in ghci). I found instance declaration cannot be overridden. and I don't

Why static method of parent class is called when subclass has already overridden it?

孤人 提交于 2019-12-30 20:31:42
问题 I am confused by the behaviour of the static method when it is overridden in the subclass. Below is the code: public class SuperClass { public static void staticMethod() { System.out.println("SuperClass: inside staticMethod"); } } public class SubClass extends SuperClass { //overriding the static method public static void staticMethod() { System.out.println("SubClass: inside staticMethod"); } } public class CheckClass { public static void main(String[] args) { SuperClass

create custom namedtuple type with extra features

Deadly 提交于 2019-12-30 19:14:29
问题 I'd like to create my own type of build-in namedtuple that has some extra features. Let's say we create a class: from collections import namedtuple MyClass = namedtuple('MyClass', 'field1 field2') It`s immutable, readable and simple. Now I can create instances of MyClass: myobj = MyClass(field1 = 1, field2 = 3.0) print(myobj.field1, myobj.field2) My extra requirement is when instance is created I'd like to check if field1 is int type and field2 is float . For example if user try to create

When we override the toString() method we should always return a string representation of the object?

强颜欢笑 提交于 2019-12-30 17:29:14
问题 In practice, the toString method should return a String representation of the object. In one project, I found some classes that override the toString method allowing return null. Like: @Override public String toString() { ....... return null; } For me, this practice is a violation to the principal propose of toString method that should return a String representation of the object. The API documentation for Object.toString() says: public String toString() Returns a string representation of the

Polymorphism and casting

泄露秘密 提交于 2019-12-30 17:19:18
问题 I want to understand polymorphism in c# so by trying out several constructs I came up with the following case: class Shape { public virtual void Draw() { Console.WriteLine("Shape.Draw()"); } } class Circle : Shape { public override void Draw() { Console.WriteLine("Circle.Draw()"); } } I understand that in order to send the Draw() message to several related objects, so they can act according to its own implementation I must change the instance to which (in this case) shape is 'pointing' to:

override of static method and final method

为君一笑 提交于 2019-12-30 11:18:08
问题 I know in Java , static method can not be overriden by the subclass. Two questions: 1. Why is that? Could anyone explain me the reason inside it? 2. Can subclass override final method in super class then? 回答1: Static methods aren't called on a particular instance - so they can't be called polymorphically. They are called on the type itself - nothing about the binding relies on any information which is only available at execution time. The point about polymorphic calls is that the method

Implementing Custom Membership user and Custom Membership Provider

梦想的初衷 提交于 2019-12-30 07:10:57
问题 References http://msdn.microsoft.com/en-us/library/6tc47t75%28v=VS.80%29.aspx http://msdn.microsoft.com/en-us/library/ms366730.aspx Question In the 2nd link precisely under heading Create a Custom Membership Provider you will note that they mention this You will need to create a custom membership provider that supports both your custom membership user type, and your custom membership data store. The GetUser and CreateUser methods of the custom membership provider can be written to return

why cant we override a base class method with private extended class method?

♀尐吖头ヾ 提交于 2019-12-30 07:06:19
问题 class One { void foo() { } } class Two extends One { private void foo() { /* more code here */ } } Why is the above snippet of code wrong? 回答1: I'm going to try to incorporate the ideas from the other answers to come up with a single answer. First off, let's take a look at what's going on in the code. A look at the code The One class has a package-private foo method: class One { // The lack of an access modifier means the method is package-private. void foo() { } } The Two class which