abstract class Student
{
private String name;
private int Rollno
private String course;
public abstract int m1()
{
}
}
abstract class Vehicle
{
abstract int getSpeed();
}
class Bike extends Vehicle
{
int getSpeed()
{
return 60;
}
}
class Car extends Vehicle
{
int getSpeed()
{
return 70;
}
}
public class TestVehicle
{
public static void main(String args[])
{
Vehicle bike = new Bike();
Vehicle car = new Car();
int bikespeed = bike.getSpeed();
int carspeed = car.getSpeed();
System.out.println("Speed of Bike is: "+bikespeed+" Km/h");
System.out.println("Speed of Car is: "+carspeed+" Km/h");
}
}
Abstract Class | Final Class |
---|---|
Inheritance can be allowed. | Inheritance cannot be allowed. |
It contains abstract method. | It cannot contain abstract method. |
Abstract method must be overridden. | Final method cannot be overridden. |
// EmpSetGet.java
public class EmpSetGet
{
private int empId;
private String name;
private int age;
private String dept;
public int getEmpId()
{
return empId;
}
public String getName()
{
return name;
}
public int getAge()
{
return age;
}
public String getDept()
{
return dept;
}
public void setEmpId( int empId)
{
this.empId = empId;
}
public void setName(String name)
{
this.name = name;
}
public void setAge( int age)
{
this.age = age;
}
public void setDept(String dept)
{
this.dept = dept;
}
}
//Employee.java
public class Employee
{
public static void main(String args[])
{
EmpSetGet emp = new EmpSetGet();
emp.setEmpId(101);
emp.setName("ABC");
emp.setAge(25);
emp.setDept("Testing");
System.out.print("Employee Id : "+emp.getEmpId() + "\nName : " + emp.getName() + "\nAge : " + emp.getAge() + "\nDepartment : "+emp.getDept());
}
}