Skip to content

Commit b276d4d

Browse files
committed
feat:Abstract Class Added
1 parent 0a15cd4 commit b276d4d

File tree

2 files changed

+87
-0
lines changed

2 files changed

+87
-0
lines changed

Inheritance/Bank_Account.java

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package Inheritance;
2+
3+
import java.util.Scanner;
4+
5+
class Account
6+
{
7+
int AccID;String HolderName;int Balance;
8+
Account(int id, String name,int bal)
9+
{
10+
this.HolderName = name;
11+
if(id >=100 && id <=999)this.AccID = id;
12+
else this.AccID = -1;
13+
if(Balance >=0)this.Balance = bal;
14+
else this.Balance = 0;
15+
}
16+
17+
}
18+
class VIPAccount extends Account
19+
{
20+
int neg_bal;
21+
VIPAccount(int AccID , String HolderName , int Balance)
22+
{
23+
super(AccID, HolderName, Balance);
24+
Scanner s = new Scanner(System.in);
25+
int credit=s.nextInt();
26+
neg_bal = s.nextInt();
27+
28+
System.out.println(Balance);
29+
setAccountBalance(neg_bal);
30+
}
31+
public int credit_amt(int amt)
32+
{
33+
super.Balance +=amt;
34+
return super.Balance;
35+
}
36+
37+
public void setAccountBalance(int neg)
38+
{
39+
System.out.println(super.AccID + " " + super.HolderName + " "+super.Balance);
40+
System.out.println("The balance can be negative but no less than -10000");
41+
}
42+
}
43+
public class Bank_Account {
44+
public static void main(String[] args) {
45+
46+
Scanner s = new Scanner( System.in);
47+
int id = s.nextInt();
48+
String name = s.next();
49+
int bal = s.nextInt();
50+
int credit = s.nextInt();
51+
int neg = s.nextInt();
52+
VIPAccount v = new VIPAccount(id,name,bal);
53+
v.
54+
}
55+
56+
}

abstract_class.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package Inheritance;
2+
abstract class A
3+
{
4+
abstract void print();
5+
}
6+
class B extends A
7+
{
8+
void print()
9+
{
10+
System.out.println("Hello");
11+
}
12+
}
13+
class C extends A
14+
{
15+
16+
void print()
17+
{
18+
System.out.println("Hello C");
19+
}
20+
}
21+
public class abstract_class {
22+
public static void main(String[] args) {
23+
A a = new B();
24+
A c = new C();
25+
a.print();
26+
c.print();
27+
Object o = 10.0;
28+
System.out.println();
29+
30+
}
31+
}

0 commit comments

Comments
 (0)