Click here to Skip to main content
15,867,973 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
public class Person
{
  private int age;
  private String name;
  public void setAge(int a)
  {
   age=a;
  }
  public void setName(String n)
  { 
   name=n;
   }
   public int getAge()
   {
    return(age);
   }
   public String getName()
   {
    return(name);
   }
}

   class Student extends person
{
  private int rollno;
  public void setRollno(int r)
  {
   rollno=r;
   }
   public int getRollno()
   {
  return(rollno);
   }
}public class Example
{
   public static void main(String []args)
    {
     Student s1=new Student();
    s1.getRollno(63); 
   
   s1.setAge(18);
  s1.setName("smit");
   
    System.out.println("roll no="+s1.getRollno());
    System.out.println("name="+s1.getName());
    System.out.println("age="+s1.getAge());
    }
}


What I have tried:

yes i have tried many ways by reinstalling java
second i have compile so many ways by writing keyword package
and by sorting java file
Posted
Updated 30-May-19 0:24am

1 solution

Java is case sensitive: "person" and "Person" are different identifiers:
Java
public class Person
{
...
}
   class Student extends person
{
...
}
Fix that, and other errors may disappear at the same time...
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900