Skip to content

Commit 21c571b

Browse files
Add files via upload
1 parent 525c10e commit 21c571b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+749
-0
lines changed

Access_modifier/A.class

1.25 KB
Binary file not shown.

Access_modifier/AM2.class

1.39 KB
Binary file not shown.

Access_modifier/AM2.java

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package Access_modifier;
2+
3+
import Inheritance.AM1 ; // AM1 is usable only after import in line 26
4+
class A{
5+
protected String a;
6+
void display(String a)
7+
{
8+
System.out.println(a);
9+
}
10+
11+
}
12+
13+
14+
class AM2
15+
{
16+
static void display()
17+
{
18+
System.out.println("Calling static method ");
19+
}
20+
21+
22+
23+
24+
public static void main(String args[]) {
25+
display();
26+
A O = new A();
27+
AM1 O1 =new AM1();
28+
O.display("Calling protected member ");
29+
30+
} }
31+
32+
33+
34+

Class_objects/Author.class

2.73 KB
Binary file not shown.

Class_objects/Book.class

2.83 KB
Binary file not shown.

Class_objects/Calculator.class

1.02 KB
Binary file not shown.

Class_objects/Employee.class

1.87 KB
Binary file not shown.

Class_objects/Employee1.class

1.75 KB
Binary file not shown.

Class_objects/Test_AUTHOR.class

2.73 KB
Binary file not shown.

Class_objects/Test_AUTHOR.java

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
package Class_objects;
2+
3+
class Author {
4+
private String name;
5+
private String email ;
6+
private char gender;
7+
Author(String name, String email , char gender){
8+
this.name = name; this.email = email; this.gender = gender;
9+
}
10+
public String getName() {
11+
return name;
12+
}
13+
public String getEmail() {
14+
return email;
15+
}
16+
public char getGender() {
17+
return gender;
18+
}
19+
public void setName(String name) {
20+
this.name = name;
21+
}
22+
public void setEmail(String email) {
23+
this.email = email;
24+
}
25+
public void setGender(char gender) {
26+
this.gender = gender;
27+
}
28+
} // end of author class
29+
30+
class Book {
31+
private String name;
32+
private Author author;
33+
private double price;
34+
private int qtyInStock;
35+
Book(String name, Author author, double price,int qtyInStock){
36+
this.name = name;
37+
this.author = author;
38+
this.price = price;
39+
this.qtyInStock = qtyInStock;
40+
}
41+
public String getName() {
42+
return name;
43+
}
44+
public Author getAuthor() {
45+
return author;
46+
}
47+
public double getPrice() {
48+
return price;
49+
}
50+
public int getQtyInStock() {
51+
return qtyInStock;
52+
}
53+
54+
public void setPrice(double price) {
55+
this.price = price;
56+
}
57+
public void setQtyInStock(int qtyInStock) {
58+
this.qtyInStock = qtyInStock;
59+
}
60+
}// end of book class
61+
public class Test_AUTHOR{
62+
public static void main(String[] args) {
63+
Book book_obj = new Book("Java - The Complete Reference",
64+
new Author("Hebert Schildt", "HS@gmail.com", 'M'), 566, 10);
65+
//1. Printing the book name, price and
66+
//qtyInStock from a Book instance. (Hint: aBook.getName())
67+
System.out.println("Name = " + book_obj.getName());
68+
System.out.println("Price = " + book_obj.getPrice());
69+
System.out.println("Number of books in stock = " + book_obj.getQtyInStock());
70+
71+
// 2. After obtaining the “Author” object, print the Author
72+
//(name, email & gender) of the book.
73+
Author tmp = book_obj.getAuthor();
74+
System.out.println("Author Information::");
75+
System.out.println("Name = " + tmp.getName());
76+
System.out.println("Email = " + tmp.getEmail());
77+
System.out.println("Gender = " + tmp.getGender());
78+
79+
}
80+
}
81+
82+

0 commit comments

Comments
 (0)