You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+37-1Lines changed: 37 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -406,13 +406,49 @@ Inheritence can be extended or inherited.
406
406
407
407
**Code3:[Interface3.java](https://github.com/disha2sinha/Object-Oriented-Programming-in-Java/blob/master/Interface/Interface3.java):** A Java program to show Interface can be extended.
408
408
409
-
###Abstract class:
409
+
# Abstract class:
410
410
A class with a pure virtual function ie, an abstract method is termed as Abstract class.In java, however the class has to be declared with abstract keyword to make it Abstract.
411
411
412
412
**Code4:[AbstractClass1.java](https://github.com/disha2sinha/Object-Oriented-Programming-in-Java/blob/master/Interface/AbstractClass1.java):** A program to illustrate use of Abstract class.
413
413
414
414
**Code5:[Abstractclass2.java](https://github.com/disha2sinha/Object-Oriented-Programming-in-Java/blob/master/Interface/Abstractclass2.java):** A program to show that java allows abstract classes without any abstract method in it.
415
+
### ABSTRACT CLASS VS INTERFACE:
415
416
417
+
|**PROPERTIES**|**ABSTRACT CLASS**|**INTERFACE**|
418
+
|:------------:|:----------------:|:-----------:|
419
+
|**Methods**|Abstract class can have abstract and non-abstract methods. From Java 8, it can have default and static methods also.|Interface can have only abstract methods.|
420
+
|**Variables**|An abstract class can have final,non-final,static,non-static variables.|Variables declared in a Java interface are by default final.Interface can have only static and final variables.|
421
+
|**Implementation**|Abstract class can provide the implementation of interface.|Interface can’t provide the implementation of abstract class.|
422
+
|**Inheritance vs Abstraction**|Abstract class can be extended using keyword “extends”.|A Java interface can be implemented using keyword “implements” |
423
+
|**Multiple implementation**|An abstract class can extend another Java class and implement multiple Java interfaces.|An interface can extend another Java interface only.|
424
+
|**Accessibility of Data Members**|A Java abstract class can have class members with access as private, protected, etc.|Members of a Java interface are public by default|
425
+
426
+
### NESTED INTERFACE:
427
+
428
+
Interfaces declared as member of a class or another interface are called member interface or nested interface.
429
+
430
+
**Code6:[NestedInterface1.java](https://github.com/disha2sinha/Object-Oriented-Programming-in-Java/blob/master/Interface/NestedInterface1.java):** Java program to demonstrate working of interface inside a class.
431
+
432
+
**Code7:[NestedInterface2.java](https://github.com/disha2sinha/Object-Oriented-Programming-in-Java/blob/master/Interface/NestedInterface2.java):** // Java program to demonstrate protected specifier for nested interface.
433
+
434
+
**Code8:[NestedInterface3.java](https://github.com/disha2sinha/Object-Oriented-Programming-in-Java/blob/master/Interface/NestedInterface3.java):** Java program to demonstrate working of interface inside another interface.
435
+
436
+
**Code9:[NestedInterface4.java](https://github.com/disha2sinha/Object-Oriented-Programming-in-Java/blob/master/Interface/NestedInterface4.java):** Java program to demonstrate an interface cannot have non-public member interface.
437
+
438
+
# NESTED CLASSES:
439
+
440
+
When a class is defined within another class, such classes are known as nested classes.
441
+
442
+
443
+
1.The scope of a nested class is bounded by the scope of its enclosing class. Thus in above example, class NestedClass does not exist independently of class OuterClass.
444
+
2.A nested class has access to the members, including private members, of the class in which it is nested. However, reverse is not true i.e. the enclosing class does not have access to the members of the nested class.
445
+
3.A nested class is also a member of its enclosing class.
446
+
4.As a member of its enclosing class, a nested class can be declared private, public, protected, or package private(default).
447
+
448
+
Nested classes are divided into two categories:
449
+
450
+
1.static nested class : Nested classes that are declared static are called static nested classes.
451
+
2.inner class : An inner class is a non-static nested class.
0 commit comments