- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Maruthi Krishna has Published 951 Articles
![Maruthi Krishna](https://www.tutorialspoint.com/assets/profiles/119958/profile/60_3780337-1641548568.png)
Maruthi Krishna
282 Views
Defining a class within an interface is allowed in Java. If the methods of an interface accept a class as an argument and the class is not used elsewhere, in such cases we can define a class inside an interface.ExampleIn the following example we have an interface with name CarRentalServices ... Read More
![Maruthi Krishna](https://www.tutorialspoint.com/assets/profiles/119958/profile/60_3780337-1641548568.png)
Maruthi Krishna
4K+ Views
Interface in Java is similar to class but, it contains only abstract methods and fields which are final and static.Since all the methods are abstract you cannot instantiate it. To use it, you need to implement this interface using a class and provide body to all the abstract methods int ... Read More
![Maruthi Krishna](https://www.tutorialspoint.com/assets/profiles/119958/profile/60_3780337-1641548568.png)
Maruthi Krishna
6K+ Views
No, you cannot have a constructor within an interface in Java.You can have only public, static, final variables and, public, abstract, methods as of Java7.From Java8 onwards interfaces allow default methods and static methods.From Java9 onwards interfaces allow private and private static methods.Moreover, all the methods you define (except above ... Read More
![Maruthi Krishna](https://www.tutorialspoint.com/assets/profiles/119958/profile/60_3780337-1641548568.png)
Maruthi Krishna
2K+ Views
Interface in Java is similar to class but, it contains only abstract methods and fields which are final and static.In a separate class you need to implement this interface and provide body for all its abstract methods.Once you implement an interface using a class, you must provide body (implement) to ... Read More
![Maruthi Krishna](https://www.tutorialspoint.com/assets/profiles/119958/profile/60_3780337-1641548568.png)
Maruthi Krishna
709 Views
An interface in Java is similar to class but, it contains only abstract methods and fields which are final and static.You can implement multiple interfaces using a single class in Java. Whenever both interfaces have same name, since all the fields of an interface are static by default, you can ... Read More
![Maruthi Krishna](https://www.tutorialspoint.com/assets/profiles/119958/profile/60_3780337-1641548568.png)
Maruthi Krishna
2K+ Views
A method which does not have body is known as abstract method. It contains only method signature with a semi colon and, an abstract keyword before it.public abstract myMethod();Yes, you can throw and exception from an abstract class.ExampleIn the following Java program, we have a two classes: one abstract class ... Read More
![Maruthi Krishna](https://www.tutorialspoint.com/assets/profiles/119958/profile/60_3780337-1641548568.png)
Maruthi Krishna
2K+ Views
Yes, the abstract methods of an interface can throw an exception.ExampleIn the following example the interface (MyInterface) contains an abstract method with name display, which throws an IOException.import java.io.IOException; abstract interface MyInterface { Â Â public abstract void display()throws IOException ; }Rules to be followedYou need to follow the rules given ... Read More
![Maruthi Krishna](https://www.tutorialspoint.com/assets/profiles/119958/profile/60_3780337-1641548568.png)
Maruthi Krishna
423 Views
A checked exception is an exception that occurs at the compile time, these are also called as compile time exceptions. These exceptions cannot simply be ignored at the time of compilation; the programmer should take care of (handle) these exceptions.An unchecked exception is an exception that occurs at the time ... Read More
![Maruthi Krishna](https://www.tutorialspoint.com/assets/profiles/119958/profile/60_3780337-1641548568.png)
Maruthi Krishna
531 Views
While a superclass method throws an exception while overriding it you need to follow the certain rules.Should throw Same exception or, sub typeIf the super-class method throws certain exception, the method in the sub-class should throw the same exception or its sub type.ExampleIn the following example, the readFile() method of ... Read More
![Maruthi Krishna](https://www.tutorialspoint.com/assets/profiles/119958/profile/60_3780337-1641548568.png)
Maruthi Krishna
1K+ Views
In Java final is the access modifier which can be used with a filed class and a method.When a method if final it cannot be overridden.When a variable is final its value cannot be modified further.When a class is finale it cannot be extended.Declaring final variable without initializationIf you declare ... Read More