Posts

Showing posts with the label Java

Java: 3 Easy programs for Class and Objects basics in Java.

Image
Programs: // 1.   Create a class Vehicle. //      a.  The class should have two fields: //          i.  no_of_seats and no_of_wheels. //      b.  Create two objects //          i.  Motorcycle and Car for this class. //      c.  Your output should show the descriptions for Car and Motorcycle package A6 ; class Vehicle {     // Initialize attributes:     int no_of_seats ;     int no_of_wheels ;     // Two-argument constructor:     Vehicle ( int seats , int wheels ) {         no_of_seats   = seats ;         no_of_wheels = wheels ;     }     // Displays values of attributes:     String display () {         return "no_of_seats = " + no_of_seats + ", no_of_wheels = " + no_of_wheels + "." ;     }   ...