Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package javaapplication10;
- public abstract class Person {
- protected String name;
- protected String phone;
- public Person(String name, String phone) {
- this.name = name;
- this.phone = phone;
- }
- public void display()
- {
- System.out.println("Name : "+name+"\nPhone Number :"+phone);
- }
- }
- package javaapplication10;
- public class Address {
- private String city;
- private String country;
- public Address(String city, String country) {
- this.city = city;
- this.country = country;
- }
- public void display()
- {
- System.out.println("City :"+city+"\nCountry: "+country);
- }
- }
- package javaapplication10;
- public class Main {
- public static void main(String[] args)
- {
- Student obj=new Student("CSE",3.64);
- obj.display();
- Address ob1=new Address("Dhaka","Bangladesh");
- ob1.display();
- Teacher obj2=new Teacher("Professor");
- obj2.display();
- Address ob4=new Address("Tangail","Bangladesh");
- ob4.display();
- }
- }
- package javaapplication10;
- public class Student extends Person {
- private String studid;
- private double cgpa;
- public Student(String s, double c) {
- super("Ahmed", "0179");
- this.studid = s;
- this.cgpa = c;
- System.out.println("Student Information: ");
- System.out.println("Studied: "+s);
- System.out.println("CGPA: "+c);
- }
- }
- package javaapplication10;
- public class Teacher extends Person {
- private String designation;
- public Teacher(String d) {
- super("Shanto","01790363394");
- designation = d;
- System.out.println("Teacher Information: ");
- System.out.println("Designation: "+d);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement