ERROR MESSAGE[non-static variables this cannot be referenced from a static contex ]
public static void main(String []args) - {
-
Product p = new Product(110,"Books",15.00,2010,"Wiliams");
-
p.setproductId(110);
-
p.setproductName("Books");
-
p.setCost(15.00);
-
p.setyearOfPublication(2010);
-
p.setpublishingHouse("Wiliams");
-
-
-
int productId = p.getproductId();
-
String productName = p.getproductName();
-
double cost = p.getCost();
-
int yearOfPublication = p.getyearOfPublication();
-
String publishingHouse = p.getpublishingHouse();
-
-
}
-
class Product
-
{
-
private int productId;
-
private String productName;
-
private double cost;
-
private int yearOfPublication;
-
private String publishingHouse;
-
-
-
public Product(int productId,String productName,double cost,int yearOfPublication,String publishingHouse)
-
{
-
this.productId = productId;
-
this.productName = productName;
-
this.cost = cost;
-
this.yearOfPublication = yearOfPublication;
-
this.publishingHouse = publishingHouse;
-
}
-
-
public void setId(int productId)
-
{
-
this.productId = productId;
-
}
-
-
public int getproductId()
-
{
-
return productId;
-
}
-
public void setproductName(String productName)
-
{
-
this.productName = productName;
-
}
-
-
public String getproductName()
-
{
-
return productName;
-
}
-
-
public void setcost(double cost)
-
{
-
this.cost = cost;
-
}
-
-
public int getcost()
-
{
-
return cost;
-
}
-
-
public void setyearOfPublication(int yearOfPublication)
-
{
-
this.yearOfPublication = yearOfPublication;
-
}
-
-
public int getyearOfPublication()
-
{
-
return yearOfPublication;
-
}
-
-
public void setpublishingHouse(String publishingHouse)
-
{
-
this.publishingHouse = publishingHouse;
-
}
-
-
public int getpublishingHouse()
-
{
-
return publishingHouse;
-
}
-
}
-
-
class Book extends Product
-
{
-
private String author;
-
private int ISBN;
-
private int numberOfPages;
-
-
-
public Book(String author, int ISBN, int numberOfPages, int productId, String productName, double cost,
-
int yearOfPublication, String publishingHouse)
-
{
-
super(productId,productName,cost,yearOfPublication,publishingHouse);
-
this.author = author;
-
this.ISBN = ISBN;
-
this.numberOfPages = numberOfPages;
-
}
-
}
-
-
class Software extends Product
-
{
-
private int RAM;
-
private int processor;
-
-
-
-
public Software(int RAM,int processor,int productId, String productName, double cost,
-
int yearOfPublication, String publishingHouse)
-
{
-
super(productId,productName,cost,yearOfPublication,publishingHouse);
-
this.RAM = RAM;
-
this.processor = processor;
-
}
-
-
-
}
-
-
}
2 2235
I can't see any error here regarding static and non-static calls. Which line is the error? Maybe you forgot to include the line containing the error in this listing?)
You don't identify the static versus non-static methods except that the java main function is static by design. If you are calling the Product class within the java main function, then that could be a problem. Try making Product a standalone class such as Product.java. Then in the java static main method instantiate the class, e.g. Product p = new Product();
Sign in to post your reply or Sign up for a free account.
Similar topics
by: baby pink |
last post by:
kindly solve the problem in article one .. its quite urgent
thanx for reading
goog luck
pink
|
by: BVM |
last post by:
Hi, All:
I have this error. It seems execution time is too long. Actually the execution time is about 30 seconds(I tested in Query analyzer). How do I solve this problem?
...
|
by: Mat |
last post by:
I am developping multi-user windows application. i use Access database.
user edit, add and delete data from database.
Request:
when an item is deleted ,added or modified by an user, all others...
|
by: Eric |
last post by:
Visual C++ 2005 Express
MVP's and experience programmer's only please!...
I need to get the number of lines in a textbox so I can insert them into a
listview. The text comes from my database...
|
by: begeiste |
last post by:
I have installed the easyPHP on Windows, but the apache server can not be started since message shows me another web server use the web port. Don't know where to find this web port or how can I solve...
|
by: jautrus |
last post by:
I would like to have div tag over list box, not list box over div tag.
I have this problem on many pages usually when I use drop down menus.
I try to solve this problem with z-index but it doesn't...
|
by: Hooyoo |
last post by:
Following are similar codes of my project:
At first I define two classes in two files:
//ClassA.h
#pragma once
#include "ClassB.h"
class ClassA
{
public:
ClassA(void){};
|
by: aintnoname |
last post by:
I have a problem with dr java.
Everything was fine until today - I got a message that no compiler is available.
I downloaded the new beta version of dr java, and now there is a compiler, but when I...
|
by: Ryan Liu |
last post by:
Hi,
I have a 100 clients/ one server application, use ugly one thread pre client
approach. And both side user sync I/O.
I frequently see the error on server side(client side code is same, but...
|
by: Hon Man |
last post by:
how can isolve this problem in my balckberry
steps to solve java.nullpointerexception
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |