Switch to full style
Java2 codes,problems ,discussions and solutions are here
Post a reply

Need Help about Inheritance

Wed Feb 04, 2009 11:51 am

java code
class Person
{
private String name;

public void setName(String n)
{
name = n;
}

public String getName()
{
return name;
}
}


class Student extends Person
{
private String stuNum;

public void setStuNum(String sn)
{
stuNum = sn;
}

public String getStuNum()
{
return stuNum;
}
}


public class TestInheritance
{
public static void main(String[] args)
{
Student stu = new Student();
stu.setName("John Smith");
stu.setStuNum("12345");
System.out.println("Student Name: " + stu.getName());
System.out.println("Student Number: " + stu.getStuNum());
}
}



I CAN GET IT RUN ?? pls tell me the solution.
why person class and student class don;t have keyword public ?
This code can be found at
Code:
http://www.learn-programming.za.net/pro ... arn08.html




Re: Need Help about Inheritance

Wed Feb 04, 2009 10:48 pm

there must be only one public class and it is the same name of the java file .

Post a reply
  Related Posts  to : Need Help about Inheritance
 What is Inheritance?!!     -  
 help me! inheritance     -  
 Inheritance C++ Example     -  
 Inheritance in c++     -  
 inheritance in c++     -  
 Inheritance in java     -  
 @AttributeOverride with Inheritance     -  
 Multiple Inheritance     -  
 single table inheritance     -  
 Inheritance & polymorphism checker code     -