Abstract Class in Java
Abstract Class in Java
File: TestAbstraction2.java
//example of abstract class that have method body
abstract class Bike{
Bike(){System.out.println("bike is created");}
abstract void run();
void changeGear(){System.out.println("gear changed");}
}
interface A{
void a();
void b();
void c();
void d();
}
class M extends B{
public void a(){System.out.println("I am a");}
public void b(){System.out.println("I am b");}
public void d(){System.out.println("I am d");}
}
class Test5{
public static void main(String args[]){
A a=new M();
a.a();
a.b();
a.c();
a.d();
}}
Test it NowOutput:I am a I am b I am c I am d
Java Package
Java package
• A java package is a group of similar types of
classes, interfaces and sub-packages.
• Package in java can be categorized in two
form, built-in package and user-defined
package.
• There are many built-in packages such as java,
lang, awt, javax, swing, net, io, util, sql etc.
• Here, we will have the detailed learning of
creating and using user-defined packages.
Advantage of Java Package
Output:Welcome to package
The -d is a switch that tells the compiler where to put the class file
i.e. it represents destination. The . represents the current folder.