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;
}

@Override
public double getArea() {
return Math.PI*getRadius()*getRadius();
}
public Circle(double radius)
{
setRadius(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;
}

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

}


import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;


public class ShapeTest {

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

Rectangle rect=(Rectangle)shape;
rect.setLength(15.0);
rect.setWidth(10.0);


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

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

}


View Tutorial



Subscribe to Tutorials

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. i'ma beginer in this android devopment tutorial ca
View Tutorial          By: vijay at 2015-08-18 05:16:54

2. I am wanting to use a Honeywell 4600g handheld sca
View Tutorial          By: bugdrvr1970 at 2012-01-25 17:27:43

3. I need a software to send messages to our members.
View Tutorial          By: M V Bhaktha at 2012-05-22 08:19:38

4. I need you to Write me a program to initialize one
View Tutorial          By: Sayed maseer at 2015-06-20 05:09:12

5. Hi
I can compile it
root$ javac -cp

View Tutorial          By: Tebogo Modiselle at 2014-10-31 08:47:09

6. sir, thanks sir. very help to me. its simple and e
View Tutorial          By: kannathasan.M at 2012-10-01 07:59:28

7. hi,
i need to connect to server named xxx,i

View Tutorial          By: annamalai at 2012-05-21 10:09:52

8. import java.io.*;
import java.util.Stack;
View Tutorial          By: jack&jill at 2011-07-26 06:40:32

9. Thanks a lot .. Great work!!
View Tutorial          By: MonamAlwerfally at 2013-03-26 14:41:29

10. Why not a simple array list of threads?
wha

View Tutorial          By: Ranadheer Machineni at 2011-08-18 12:30:35