OO Concepts, Terms and Definitions


Basic Java

  • Inheritance: In Java, inheritance is done with the keyword "extends" after a class name in a class declaration
      Example:
    
        class MobileRectangle extends Rectangle {
         
           // field and methods definitions to add
           // to those of existing class Rectangle
    
        }
    
  • Degenerate classes
    You can create a class in Java that has no fields... only methods. Such a class would serve as a library... a collection of methods related in their function (like a collection of Math functions, for example). You can declare all the methods to be static and then the methods can be called without creating an object of the class. You use the class name followed by the methods name to call these methods.
       Example:
    
          public class Libra {
      
             public static int mult5 ( int n ) {
                return n*5;
             }
    
          }
    
       This can be called this way:
    
          System.out.println( Libra.mult5(12) ) ;
    
       This will print 60 for the example given.
    
  • Using the main method and class
    Often Java programmers will use the main method, and the class containing it, to do nothing more that create objects of other classes and set the computation in motion. Such a main class will not contain much code. It might look something like this:
    
         public class KickItOff {
    
            public static void main (String[] args) {
    
               SomeClass ob1 = new SomeClass();
               OtherClass ob2 = new OtherClass();
    
    	   ob1.DoYourThing();
               ob2.PerformActions();
    
            }
    
    
         }