MainClass_SubClasses1.htm
Objectives :
  • Main Class with an Entry Point to the application / project
  • Use of Subclasses in the context of extended classes and  overloading or overriding member methods:  Static methods in the Subclass remains unchanged and doest not mutate.
    • Overloading : parameters changes in the methods, keeping rest;
    • Overriding : Output or Content Cnages
Screen shot showing, entry point and base class of an application.

Super Class and Subclasses

Instance of the Class University, and calling a static /standard method

Complete Code:

/**
*
*/
import java.io.*;
import javax.swing.JOptionPane;
import java.net.URI;
/**
* @author Manas9
*
*/
public class ClassTemplate1 {
/**
*
*/
public ClassTemplate1() {
// TODO Auto-generated constructor stub

}
public static void main(String[] args)
throws Exception {
// TODO Auto-generated method stub
try {
//
Dept1 myDept1 = new Dept1();
Dept2 myDept2 = new Dept2();
// Series 1 extension
University myUniversity1 = myDept1;
University.printUnivMethod();
myUniversity1.deptNameMethod();
//Series 2 extension
University myUniversity2 = myDept2;
University.printUnivMethod();
myUniversity2.deptNameMethod();
//
} catch (NumberFormatException exc) {
//
}
}

}// end of class template
// New sub class under Template1 area
// University is a super class with reference to
//Dept1 and Dept2 subclasses
class University {
public static void printUnivMethod() {
System.out.println("The static method in University");
}
public void deptNameMethod() {
System.out.println("The instance method in University");
}
}
// Class extended
class Dept1 extends University {
public static void printUnivMethod() {
System.out.println("The static method in not mutated");
}
public void deptNameMethod() {
System.out.println("The instance method in Dept1");
}
}
//Class extended
class Dept2 extends University {
public static void printUnivMethod() {
System.out.println("The static method in not mutated");
}
public void deptNameMethod() {
System.out.println("The instance method in Dept2");
}
}
 

Runtime views: