Animal
, it can define common properties like Age
and Weight
, while specific animals like Dog
and Cat
can inherit from it and add their unique behaviors.abstract
keyword. Here's a quick look at the syntax:1public abstract class Animal
2{
3 // Common properties
4 public int Age { get; set; }
5
6 // Abstract method
7 public abstract void MakeSound();
8}
9
1public abstract class Vehicle
2{
3 public string Brand { get; set; }
4
5 // Abstract method
6 public abstract void Drive();
7}
8
Vehicle
is an abstract class that defines a property Brand
and an abstract method Drive()
that must be implemented in subclasses.1public abstract class Shape
2{
3 public abstract double Area(); // Abstract method
4}
5
6public class Circle : Shape
7{
8 public double Radius { get; set; }
9
10 public override double Area() // Implementation
11 {
12 return Math.PI * Radius * Radius;
13 }
14}
15
Shape
class defines an abstract Area()
method, and Circle
provides an implementation for it!sealed
modifier comes into play here. If you have a class that inherits from an abstract class, you can seal it to prevent other classes from deriving from it:1public sealed class Square : Shape
2{
3 public double Side { get; set; }
4
5 public override double Area()
6 {
7 return Side * Side;
8 }
9}
10
*
) takes precedence over the addition (+
), which means 3 * 4
is calculated first. This results in result
being 14
, not 20
. Fascinating, right?===
(strict equality), !==
(strict inequality), <
, and >
. These operators return a Boolean value (true or false) based on the comparison.&&
(AND), ||
(OR), and !
(NOT), help you create complex conditions in your statements. They play a big role in control flow.&
, |
, ^
, ~
). They're less common but can be powerful when used correctly.=
, +=
, -=
, etc., and are used to assign values to variables. They might seem straightforward, but their precedence can sometimes lead to confusion.a - b - c
, it calculates as (a - b) - c
.10 * 2
is evaluated first, followed by the addition.1let a = true;
2let b = false;
3let c = true;
4
5let result = a || b && c;
6console.log(result); // Outputs: true
7
b && c
evaluates before a ||
.+
and -
have higher precedence over *
and /
.