0% found this document useful (0 votes)
20 views2 pages

Java Programming Concepts Explained

Uploaded by

Maya Joshi
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views2 pages

Java Programming Concepts Explained

Uploaded by

Maya Joshi
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

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')
[Link]("Vowel");
else
[Link]("Consonant");
}
}

2. Static Import Demonstration


class StaticImportDemo {
public static void main(String[] args) {
[Link]([Link](25));
[Link]([Link](2,3));
[Link]([Link](-10));
}
}

3. Constructor Chaining
class Chain {
Chain() {
this(10);
[Link]("Default constructor");
}
Chain(int x) {
this(x,20);
[Link]("One parameter constructor");
}
Chain(int x,int y) {
[Link]("Two parameter constructor");
}
public static void main(String[] args) {
new Chain();
}
}

4. Constructor, Static Block, Init Block


class Blocks {
static {
[Link]("Static block");
}
{
[Link]("Init block");
}
Blocks() {
[Link]("Constructor");
}
public static void main(String[] args) {
new Blocks();
new Blocks();
}
}

5. All Types of Inheritance


class A {
void showA() {
[Link]("Class A");
}
}
class B extends A {
void showB() {
[Link]("Class B");
}
}
class C extends B {
void showC() {
[Link]("Class C");
}
}
class D {
void showD() {
[Link]("Class D");
}
}
interface E {
void showE();
}
class F extends D implements E {
public void showE() {
[Link]("Interface E");
}
}
public class InheritanceDemo {
public static void main(String[] args) {
C c=new C();
[Link]();
[Link]();
[Link]();
F f=new F();
[Link]();
[Link]();
}
}

You might also like