Classes

Category : Java | Sub Category : Object- oriented Programming | By Prasad Bonam Last updated: 2020-11-28 13:13:34 Viewed : 508


Classes:

  • Java is an object-oriented language
  • Its constructs represent concepts from the real world.
  • Each Java program has at least one class that knows how to do certain actions or has properties
  • Classes in Java may have methods and properties (a.k.a. attributes or fields)

                                                Example 1: Car Class



    Example 2: Creating Car Objects

    Now the variables car1 and car2 represent new instances of Car:

    car1.color=“blue”; car2.color=“red”;!

    These two Car instances are created with the new operator:

     Car car1 = new Car();

    Car car2 = new Car();

    Search
    Related Articles

    Leave a Comment: