Comment on Tutorial - Abstract classes in Java By Kamini

Comment Added by : Vikash K Agarwal

Comment Added at : 2011-11-02 12:02:50

Comment on Tutorial : Abstract classes in Java By Kamini
Here i posted a good example with spring. Here really implementation of OOPS.
public abstract class Shape {
public abstract double getArea();
public void printInfo()
System.out.printf("%s with area of %,.2f%n",getClass().getSimpleName(), getArea());

public class Circle extends Shape {

private double radius;

public double getRadius() {
return radius;

public void setRadius(double radius) {
this.radius = radius;

public double getArea() {
return Math.PI*getRadius()*getRadius();
public Circle(double radius)


public class Rectangle extends Shape {

private double length,width;

public double getLength() {
return length;

public void setLength(double length) {
this.length = length;

public double getWidth() {
return width;

public void setWidth(double width) {
this.width = width;

public double getArea() {
return getLength()*getWidth();
public Rectangle(double length,double width)
public Rectangle(){}


import org.springframework.context.ApplicationContext;

public class ShapeTest {

* @param args
public static void main(String[] args) {
ApplicationContext applicationContext=new ClassPathXmlApplicationContext("spring.xml");
Shape shape=(Shape)applicationContext.getBean("Rectangle");

Rectangle rect=(Rectangle)shape;

Shape shape2=(Shape)applicationContext.getBean("Rectangle");

Shape shape1=(Shape)applicationContext.getBean("Circle");


View Tutorial

Related Tutorials

Program using concept of byte long short and int in java

Update contents of a file within a jar file

Tomcat and httpd configured in port 8080 and 80

Java File

Java String

Count number of vowels, consonants and digits in a String in Java

Reverse a number in Java

Student marks calculation program in Java

Handling Fractions in Java

Calculate gross salary in Java

Calculate average sale of the week in Java

Vector in Java - Sample Program

MultiLevel Inheritance sample in Java

Multiple Inheritance sample in Java

Java program using Method Overriding

Archived Comments

1. aoa i am for the first time learning programing pl
View Tutorial          By: manaal siddiqui at 2011-11-02 09:38:00

2. i want to knew about byte datatype. why did not by
View Tutorial          By: pankaj kr tiwari at 2011-12-02 04:37:43

3. # include <iostream.h>
int main ()
View Tutorial          By: nazarine at 2011-07-06 06:17:10

4. if a class is declared as abstract and it contains
View Tutorial          By: nagaraj at 2012-04-25 17:12:30

5. Nice explanation.But please explain left shift an
View Tutorial          By: Ramesh Kanagaraj at 2013-03-28 14:27:30

6. This text is a plagiary of part of K&R ANSI C
View Tutorial          By: c_apprientice at 2010-11-13 07:30:11

7. thanks for suppporting us
View Tutorial          By: sonia at 2010-11-29 00:46:56

8. what about strings in J2ME ?
View Tutorial          By: Swapnil at 2012-07-20 09:19:15

9. "If you enter zero, the assert() macro forces
View Tutorial          By: czx at 2010-09-17 07:23:20

10. It gives strange result when we use == as delimite
View Tutorial          By: Amit at 2010-05-07 05:03:41