1.
Vowel or Consonant
class VowelConsonant {
public static void main(String[] args) {
char ch = 'a';
if (ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u'||ch=='A'||ch=='E'
||ch=='I'||ch=='O'||ch=='U')
System.out.println("Vowel");
else
System.out.println("Consonant");
}
}
2. Static Import Demonstration
class StaticImportDemo {
public static void main(String[] args) {
System.out.println(Math.sqrt(25));
System.out.println(Math.pow(2,3));
System.out.println(Math.abs(-10));
}
}
3. Constructor Chaining
class Chain {
Chain() {
this(10);
System.out.println("Default constructor");
}
Chain(int x) {
this(x,20);
System.out.println("One parameter constructor");
}
Chain(int x,int y) {
System.out.println("Two parameter constructor");
}
public static void main(String[] args) {
new Chain();
}
}
4. Constructor, Static Block, Init Block
class Blocks {
static {
System.out.println("Static block");
}
{
System.out.println("Init block");
}
Blocks() {
System.out.println("Constructor");
}
public static void main(String[] args) {
new Blocks();
new Blocks();
}
}
5. All Types of Inheritance
class A {
void showA() {
System.out.println("Class A");
}
}
class B extends A {
void showB() {
System.out.println("Class B");
}
}
class C extends B {
void showC() {
System.out.println("Class C");
}
}
class D {
void showD() {
System.out.println("Class D");
}
}
interface E {
void showE();
}
class F extends D implements E {
public void showE() {
System.out.println("Interface E");
}
}
public class InheritanceDemo {
public static void main(String[] args) {
C c=new C();
c.showA();
c.showB();
c.showC();
F f=new F();
f.showD();
f.showE();
}
}