Preview:
public class Inheritance {
    private String name;
    private int age;
    public String getName(){
        return name;
    }
    public void setName(String name){
        this.name=name;

    }
    public int getAge(){
        return age;

    }
    public void setAge(int age){
        this.age=age;
    }
    public String tostring(){
    return "name:"+name+"\n age:"+age;
}

    
}


public class Student extends Inheritance{
    private int rollno;
    public int getrollno(){
        return rollno;
    }
    public void setRollNo(int rollno){
        this.rollno=rollno;

    }
    public String tostring(){
        return super.tostring()+"\n"+"roll number:"+rollno;
    }
}


public class Main{
    public static void main(String[] args){
        Student s1=new Student();
        System.out.println(s1+"\n");
        s1.setName("person1");
        s1.setAge(18);
        s1.setRollNo(101);
        System.out.println(s1);
    }
} 
downloadDownload PNG downloadDownload JPEG downloadDownload SVG

Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!

Click to optimize width for Twitter