class MyClass {
static staticProperty: number = 10;
static staticMethod(): void {
console.log('This is a static method');
}
instanceProperty: string;
constructor(value: string) {
this.instanceProperty = value;
}
instanceMethod(): void {
console.log(`Instance method called with ${this.instanceProperty}`);
}
}
// Accessing static property and method without creating an instance
console.log(MyClass.staticProperty); // Output: 10
MyClass.staticMethod(); // Output: This is a static method
// Creating an instance and accessing instance property and method
const myInstance = new MyClass('Hello');
console.log(myInstance.instanceProperty); // Output: Hello
myInstance.instanceMethod(); // Output: Instance method called with Hello