Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 12-01-2007, 08:47 AM
khamuruddeen's Avatar
Member
 
Join Date: Dec 2007
Posts: 24
khamuruddeen is on a distinguished road
constructors
class student
{
String name;
String dep;
int no;

public student(String fn,String de,int n)
{
name=fn;
dep=de;
no=n;
display();
}
public student()
{

}
public void changedep(String dep)
{
this.dep=dep;
System.out.println("dep of student is changed to "+dep);
display();
}
public void display()
{
System.out.println("Name: "+name);
System.out.println("Department: "+dep);
System.out.println("Number: "+no);
}
}

public class cla extends student
{
int nostu=0;
public void joinstu(String n1,String d1,int no1)
{
student st=new student(n1,d1,no1);
nostu++;
System.out.print("The new Student "+n1);System.out.print(" with no"+no1);System.out.print("is addeed to"+d1);System.out.print("departmenet in the class");
}
public void nostud()
{
System.out.println("No of students is "+nostu);
}
public static void main(String args[])
{
joinstu("kami","ece",39);
nostud();
changedep("cse");
}
}







its my program iam coming errors are




D:\java>javac cla.java
cla.java:47: non-static method joinstu(java.lang.String,java.lang.String,int) ca
nnot be referenced from a static context
joinstu("kami","ece",39);
^
cla.java:48: non-static method nostud() cannot be referenced from a static conte
xt
nostud();
^
cla.java:49: non-static method changedep(java.lang.String) cannot be referenced
from a static context
changedep("cse");
^
3 errors

D:\java>



then what i hav 2 do pls advice
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 12-01-2007, 09:07 AM
Senior Member
 
Join Date: Jul 2007
Posts: 1,222
hardwired is on a distinguished road
Code:
public class StudExtension extends Student { int nostu=0; public void joinstu(String n1,String d1,int no1) { Student st=new Student(n1,d1,no1); nostu++; System.out.print("The new Student "+n1); System.out.print(" with no"+no1); System.out.print("is addeed to"+d1); System.out.print("departmenet in the class"); } public void nostud() { System.out.println("No of students is "+nostu); } public static void main(String[] args) { StudExtension se = new StudExtension(); se.joinstu("kami","ece",39); se.nostud(); se.changedep("cse"); } } class Student { ... public Student() { this(null, null, 0); }
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 12-01-2007, 05:15 PM
khamuruddeen's Avatar
Member
 
Join Date: Dec 2007
Posts: 24
khamuruddeen is on a distinguished road
reply
thank u for ur suggestion sir..;
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help with constructors Minime New To Java 3 04-09-2008 09:59 AM
Initializing variables using constructors Java Tip Java Tips 0 01-13-2008 10:28 PM


All times are GMT +3. The time now is 03:45 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org