I am attaching my coding.
Point.java first
public class Point{
int x;
int y;
public Point(int k, int j)
{
x=k;
y=j;
System.out.println("Constructing a Point ");
}
}
Next GeometricShape.java
public class GeometricShape
{
Point center;
public GeometricShape(int w, int v)
{
System.out.println("Constructing a GeometricShape");
//point p = new Point();
w = center.x;
v = center.y;
}
public void displayCenter()
{
System.out.println("X and Y coordinates of center are" + center.x + center.y);
}
}
Next Rectangle.java
public class Rectangle extends GeometricShape
{
int width;
int height;
public int a;
public int b;
public int c;
public int d;
public Rectangle(int w, int v) {
super(w, v);
// TODO Auto-generated constructor stub
}
public Rectangle(int x, int y,int z, int w) {
super(x, y);
x =w;
int v = 0;
y= v;
z = width;
w = height;
System.out.println("Constructing a Rectangle");
}
}
Next Square.java
public class Square extends Rectangle
{
String color;
private String col;
public Square(int x, int y, int z, int w, String col) {
super(x, y, z, w);
//int c;
//int d;
//int b;
// TODO Auto-generated constructor stub
Rectangle r = new Rectangle(a, b, c, d);
r.a = x;
r.b = y;
r.c =width;
r.d = height;
}
public Square(int w, int v, String color) {
super(w, v);
this.color = color;
}
//public Square() {
// TODO Auto-generated constructor stub
//super(x,y,z,w);
//}
//public Square() {
// TODO Auto-generated constructor stub
// Square s = new Square();
// s.center = (x,y);
//}
//public void showColor()
//{
//
//}
public void showColor(String string) {
// TODO Auto-generated method stub
System.out.println("Color of the square is : " + col);
}
}
Finally Main Program InheritProgram.java
public class InheritProgram {
public static void main (String[] args)
{
Square s = new Square(0, 0, 0, 0, null);
s.center.x = 10;
s.center.y = 20;
s.width = 15;
s.height = 15;
s.color = "blue";
s.displayCenter();
s.showColor("blue");
}
}
I am receiving a null pointer exception error in numerous file. I would appreciate any guidance on this matter.
Precise error message is as follows:-
Constructing a GeometricShape
Exception in thread "main" java.lang.NullPointerException
at GeometricShape.<init>(GeometricShape.java:11)
at Rectangle.<init>(Rectangle.java:20)
at Square.<init>(Square.java:6)
at InheritProgram.main(InheritProgram.java:4)
Thanks
Farukh
This post has been edited by farukh36: 26 August 2009 - 12:05 AM

New Topic/Question
Reply




MultiQuote






|