Joined: Thu Jan 22, 2009 3:52 am Posts: 4 Has thanked: 0 time Have thanks: 0 time
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 http://www.learn-programming.za.net/pro ... arn08.html
msi_333
Question subject: Re: Need Help about Inheritance
Posted: Wed Feb 04, 2009 10:48 pm
Joined: Tue Mar 27, 2007 10:55 pm Posts: 2279 Location: Earth Has thanked: 39 time Have thanks: 61 time
there must be only one public class and it is the same name of the java file .
_________________ Currenlty programming with : java , html , php , and javascript . (OCJP-6 certified )