A Sealed is a modifer in .NET.The sealed modifier is equivalent to marking a class with the final keyword in Java.We can use this for the following reasons.
1. when youn want to provide security for the class.you declare sealed class.If you declare sealed class the class can not inerited to other class.
2. The sealed modifier is used to prevent derivation from a class. An error occurs if a sealed class is specified as the base class of another class. A sealed class cannot also be an abstract class.
using System;
sealed class SealedClass{
public int x;
public int y;
}
class MainClass{
static void Main(){
SealedClass sc = new SealedClass();
sc.x = 110;
sc.y = 150;
Console.WriteLine("x = {0}, y = {1}", sc.x, sc.y);
}
}
Output :
x = 110, y = 150
Showing posts with label Common. Show all posts
Showing posts with label Common. Show all posts
Monday, July 21, 2008
Sunday, July 20, 2008
Abstract Class
1. Abstract classes are classes that contain one or more abstract
methods.
2. An abstract method is a method that is declared, but contains
no implementation.
3. Abstract classes may not be instantiated, and require subclasses to
provide implementations for the abstract methods.
Let's look at an example of an abstract class, and an abstract method.
Suppose we were modeling the behavior of animals, by creating a class hierachy that started with a base class called Animal. Animals are capable of doing different things like flying, digging and walking, but there are some common operations as well like eating and sleeping. Some common operations are performed by all animals, but in a different way as well. When an operation is performed in a different way, it is a good candidate for an abstract method (forcing subclasses to provide a custom implementation). Let's look at a very primitive Animal base class, which defines an abstract method for making a sound (such as a dog barking, a cow mooing, or a pig oinking).
public abstract Animal
{
public void eat(Food food)
{
// do something with food....
}
public void sleep(int hours)
{
try
{
// 1000 milliseconds * 60 seconds * 60 minutes * hours
Thread.sleep ( 1000 * 60 * 60 * hours);
}
catch (InterruptedException ie) { /* ignore */ }
}
public abstract void makeNoise();
}
Note that the abstract keyword is used to denote both an abstract method, and an abstract class. Now, any animal that wants to be instantiated (like a dog or cow) must implement the makeNoise method - otherwise it is impossible to create an instance of that class. Let's look at a Dog and Cow subclass that extends the Animal class.
public Dog extends Animal
{
public void makeNoise() { System.out.println ("Bark! Bark!"); }
}
public Cow extends Animal
{
public void makeNoise() { System.out.println ("Moo! Moo!"); }
}
Now you may be wondering why not declare an abstract class as an interface, and have the Dog and Cow implement the interface. Sure you could - but you'd also need to implement the eat and sleep methods. By using abstract classes, you can inherit the implementation of other (non-abstract) methods. You can't do that with interfaces - an interface cannot provide any method implementations.
methods.
2. An abstract method is a method that is declared, but contains
no implementation.
3. Abstract classes may not be instantiated, and require subclasses to
provide implementations for the abstract methods.
Let's look at an example of an abstract class, and an abstract method.
Suppose we were modeling the behavior of animals, by creating a class hierachy that started with a base class called Animal. Animals are capable of doing different things like flying, digging and walking, but there are some common operations as well like eating and sleeping. Some common operations are performed by all animals, but in a different way as well. When an operation is performed in a different way, it is a good candidate for an abstract method (forcing subclasses to provide a custom implementation). Let's look at a very primitive Animal base class, which defines an abstract method for making a sound (such as a dog barking, a cow mooing, or a pig oinking).
public abstract Animal
{
public void eat(Food food)
{
// do something with food....
}
public void sleep(int hours)
{
try
{
// 1000 milliseconds * 60 seconds * 60 minutes * hours
Thread.sleep ( 1000 * 60 * 60 * hours);
}
catch (InterruptedException ie) { /* ignore */ }
}
public abstract void makeNoise();
}
Note that the abstract keyword is used to denote both an abstract method, and an abstract class. Now, any animal that wants to be instantiated (like a dog or cow) must implement the makeNoise method - otherwise it is impossible to create an instance of that class. Let's look at a Dog and Cow subclass that extends the Animal class.
public Dog extends Animal
{
public void makeNoise() { System.out.println ("Bark! Bark!"); }
}
public Cow extends Animal
{
public void makeNoise() { System.out.println ("Moo! Moo!"); }
}
Now you may be wondering why not declare an abstract class as an interface, and have the Dog and Cow implement the interface. Sure you could - but you'd also need to implement the eat and sleep methods. By using abstract classes, you can inherit the implementation of other (non-abstract) methods. You can't do that with interfaces - an interface cannot provide any method implementations.
Wednesday, March 12, 2008
Setting Environment Variables
An instruction stored in the MS-DOS environment that controls, for example, how to display the DOS prompt, where to store any temporary files, and the path of directories that DOS searches to find commands. The PATH, COMSPEC, PROMPT, and SET commands in the AUTOEXEC.BAT file all define environment variables.
Environment variables are strings that contain information such as drive, path, or file name. They control the behavior of various programs. For example, the TEMP environment variable specifies the location in which programs place temporary files.
In Windows 95/98/ME, append these lines to the end of your c:\autoexec.bat using notepad, and then reboot your computer:
1. set Temp=%USERPROFILE%\Local Settings\Temp
set TMP=%USERPROFILE%\Local~1\Temp
(Syntax : set variableName=variableValue)
In Windows NT/2000/XP, follow the following steps:
1. Open Control Panel
2. Click the System icon and the window pops up
3. Go to the Advanced pane

4. Click the Environment Variables button

5. There are two seperated windows showing two sets of environment variables. Select the "new" button for the upper window to create a new environment variable.Select the "Edit" button for the upper window to edit an existing environment variable. Probably you need to create the "Temp" and "TEMP" variable, and edit the "PATH" variable.


6. For Example the value of "TEMP" will be %USERPROFILE%\Local Settings\Temp
7. The value of "TMP" will be %USERPROFILE%\Local~1 \Temp.
8. You should add these values to the beginning of your "PATH" variable. If you want to specify any path of the software ,you can set using the path vairable.
For Ex :
set path=C:\Program Files\Java\jdk1.5.0_07;C:\bea\jdk142_05;
The above path specify the path od Java Software.
common predefined environment variables :
Environment variables are strings that contain information such as drive, path, or file name. They control the behavior of various programs. For example, the TEMP environment variable specifies the location in which programs place temporary files.
In Windows 95/98/ME, append these lines to the end of your c:\autoexec.bat using notepad, and then reboot your computer:
1. set Temp=%USERPROFILE%\Local Settings\Temp
set TMP=%USERPROFILE%\Local~1\Temp
(Syntax : set variableName=variableValue)
In Windows NT/2000/XP, follow the following steps:
1. Open Control Panel
2. Click the System icon and the window pops up

3. Go to the Advanced pane

4. Click the Environment Variables button

5. There are two seperated windows showing two sets of environment variables. Select the "new" button for the upper window to create a new environment variable.Select the "Edit" button for the upper window to edit an existing environment variable. Probably you need to create the "Temp" and "TEMP" variable, and edit the "PATH" variable.


6. For Example the value of "TEMP" will be %USERPROFILE%\Local Settings\Temp
7. The value of "TMP" will be %USERPROFILE%\Local~1 \Temp.
8. You should add these values to the beginning of your "PATH" variable. If you want to specify any path of the software ,you can set using the path vairable.
For Ex :
set path=C:\Program Files\Java\jdk1.5.0_07;C:\bea\jdk142_05;
The above path specify the path od Java Software.
common predefined environment variables :
Subscribe to:
Posts (Atom)