Monday, 29 April 2013

OOPS Concepts

OOPS Concepts

1. We have two classes BaseClass and childClass, ChildClass inheret base class. If we make the object of child class then which class counstructor called first?
Ans: Base class constructor will be call first.

[Image: BaseClassConstructorCalledFirst.png]


2. Can we declare an Abstract method in non-abstract class?
Ans: No
[Image: CanWeDeclareAbstractMethodInNonAbstractClass-Error.png]


3. Can we give the return type of constructor?
Ans: No
[Image: CreateFunctionSameAsClassName1Error.png]


4. If we have an abstract method in base class, then we must need to override(or use new keyword) it or not?
Ans: Yes, if we not override it then it give error.
[Image: Error-without-override-abstract-Functions.png]


5. We know that Base class constructor called first. But if we creating object with parameters, and base class have both constructor default and parameterized, then which base class constructor call first.
Ans: Base class default constructor called first.
[Image: ParamatirizedConstructor1.png]


6. Then what you can do that base class parameterized constructor call first.
Ans: We can use "Base" keyword
[Image: UseOfBaseKeywordWithConstructor.png]

Sunday, 7 April 2013

How to limit TextBox with Minimum and Maximum Integers Range

Suppose i have a requirement to accept my textbox with integers range between minimum & maximum limits. How can i achieve it?

Here is the solution using Java Script.


<script type="text/javascript">
function minmax(value, min, max)
{
    if(parseInt(value) < 0 || isNaN(value))
        return 0;
    else if(parseInt(value) > 100)
        return 100;
    else return value;
}
</script>
<input type="text" name="textWeight" id="txtWeight" maxlength="5" onkeyup="this.value = minmax(this.value, 0, 100)"/>