- 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
Found 4338 Articles for Java 8
2K+ Views
Following are various methods of Object class −protected Object clone() - Used to create and return a copy of this object. boolean equals(Object obj) - Used to indicate whether some other object is "equal to" this one.protected void finalize() - garbage collector calls this method on an object when it determines that there are no more references to the object.Class getClass() - Used to get the runtime class of this Object.int hashCode() - Used to get a hash code value for the object.void notify() - Used to wake up a single thread that is waiting on this object's monitor.void notifyAll() - ... Read More
4K+ Views
Yes, an overridden method can have a different access modifier but it cannot lower the access scope.The following rules for inherited methods are enforced -Methods declared public in a superclass also must be public in all subclasses.Methods declared protected in a superclass must either be protected or public in subclasses; they cannot be private.Methods declared private are not inherited at all, so there is no rule for them.
3K+ Views
We can declare an interface in another interface or class. Such an interface is termed as a nested interface.The following are the rules governing a nested interface.A nested interface declared within an interface must be public.A nested interface declared within a class can have any access modifier.A nested interface is by default static.Following is an example of a nested interface.ExampleLive Democlass Animal { interface Activity { void move(); } } class Dog implements Animal.Activity { public void move() { System.out.println("Dogs can walk and run"); } } public class Tester { ... Read More
5K+ Views
An abstract class can contain both abstract and non-abstract methods, whereas an Interface can have only abstract methods. Abstract classes are extended, while Interfaces are implemented. Read through this article to find out the other differences between an Abstract Class and an Interface and how they are used in real programs.What is an Abstract Class?An abstract class acts as a template that stores the methods and data members of a program. You should use an abstract class when you expect that it will inherited by different sub-classes with common methods and fields.Abstract classes may or may not contain abstract methods, ... Read More
393 Views
Java 8 introduces a new concept of default method implementation in interfaces. This capability is added for backward compatibility so that old interfaces can be used to leverage the lambda expression capability of Java 8.For example, ‘List’ or ‘Collection’ interfaces do not have ‘forEach’ method declaration. Thus, adding such method will simply break the collection framework implementations. Java 8 introduces default method so that List/Collection interface can have a default implementation of forEach method, and the class implementing these interfaces need not implement the same. An interface can also have static helper methods from Java 8 onwards
810 Views
EncapsulationEncapsulation is one of the four fundamental OOP concepts. The other three are inheritance, polymorphism, and abstraction.Encapsulation in Java is a mechanism for wrapping the data (variables) and code acting on the data (methods) together as a single unit. In encapsulation, the variables of a class will be hidden from other classes and can be accessed only through the methods of their current class. Therefore, it is also known as data hiding.To achieve encapsulation in Java −Declare the variables of a class as private.Provide public setter and getter methods to modify and view the variables values.AbstractionAbstraction is the quality of ... Read More
222 Views
Yes, a variable can be downcast to its lower range substitute by casting. It may lead to data loss although. See the example below −Example Live Demopublic class Tester { public static void main(String[] args) { int a = 300; byte b = (byte)a; System.out.println(b); } }OutputIt will print output as44
14K+ Views
Method overriding is an example of runtime polymorphism. In method overriding, a subclass overrides a method with the same signature as that of in its superclass. During compile time, the check is made on the reference type. However, in the runtime, JVM figures out the object type and would run the method that belongs to that particular object.ExampleSee the example below to understand the concept − Live Democlass Animal { public void move() { System.out.println("Animals can move"); } } class Dog extends Animal { public void move() { System.out.println("Dogs can walk and ... Read More