Skip to content

Commit d17d536

Browse files
committed
default and parameterized constructor
1 parent fbdda86 commit d17d536

1 file changed

Lines changed: 25 additions & 0 deletions

File tree

OOPs/constructor/Book_1.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package constructor;
2+
3+
import java.sql.SQLOutput;
4+
5+
class Book_2 {
6+
double price;
7+
String title;
8+
9+
Book_2(){
10+
price = 99.9;
11+
title = "Java Programming";
12+
}
13+
Book_2(double price, String title) {
14+
this.price = price;
15+
this.title = title;
16+
}
17+
18+
static void main() {
19+
Book_2 book_1 = new Book_2();
20+
Book_2 book_2 = new Book_2(120.46, "Data Structures");
21+
22+
System.out.println("Book 1: " + book_1.title + " with price $" + book_1.price);
23+
System.out.println("Book 2: " + book_2.title + " with price $" + book_2.price);
24+
}
25+
}

0 commit comments

Comments
 (0)