Skip to content

Commit 23876ff

Browse files
committed
Add Abstract Class and Methods
1 parent 03a0f19 commit 23876ff

File tree

2 files changed

+74
-0
lines changed

2 files changed

+74
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
## Getting Started
2+
3+
Welcome to the VS Code Java world. Here is a guideline to help you get started to write Java code in Visual Studio Code.
4+
5+
## Folder Structure
6+
7+
The workspace contains two folders by default, where:
8+
9+
-`src`: the folder to maintain sources
10+
-`lib`: the folder to maintain dependencies
11+
12+
Meanwhile, the compiled output files will be generated in the `bin` folder by default.
13+
14+
> If you want to customize the folder structure, open `.vscode/settings.json` and update the related settings there.
15+
16+
## Dependency Management
17+
18+
The `JAVA PROJECTS` view allows you to manage your dependencies. More details can be found [here](https://github.com/microsoft/vscode-java-dependency#manage-dependencies).
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
// ? Abstract Method
2+
// * Method that is declared without an implementation
3+
4+
// ? Abstract Class
5+
// * Class includes abstract methods
6+
// * Even one abstract method makes the class abstract
7+
// * Used to provide a common definition of a base class that multiple derived classes can share
8+
// Eg: Shape class is a base class for Circle, Rectangle, Triangle, etc.
9+
10+
// Possible to create a reference of an abstract class
11+
// But cannot create an object of an abstract class
12+
13+
// Abstract Class
14+
abstractclassParent{
15+
16+
publicParent(){
17+
System.out.println("I am a constructor of Parent class");
18+
}
19+
20+
publicvoidsayHello(){
21+
System.out.println("Hello");
22+
}
23+
24+
// Abstract method
25+
abstractpublicvoidgreet(); // or public abstract void greet(); --> Preferred
26+
27+
}
28+
29+
classChildextendsParent{
30+
31+
@Override
32+
publicvoidgreet(){
33+
System.out.println("Good Morning");
34+
}
35+
36+
}
37+
38+
abstractclassChild2extendsParent{
39+
40+
publicvoidth(){
41+
System.out.println("Good Morning");
42+
}
43+
}
44+
45+
publicclassAbstract{
46+
publicstaticvoidmain(String[] args){
47+
48+
Parentp = newParent(); // Error because Parent is abstract class
49+
50+
Childc = newChild();
51+
c.greet(); // Good Morning
52+
53+
Child2c2 = newChild2(); // Error because Child2 is abstract class
54+
55+
}
56+
}

0 commit comments

Comments
(0)