- 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
Do we need forward declarations in Java?
Forward declarations means the declaration of a method or variable prior to its implementation. Such declaration is necessary in C/C++ programming language in order to be able to use a variable or object before its implementation. In case, if we want to use a library code, then we need to create its header file and use it. But this is not a case in Java.
Java allows using a variable, class prior to its declaration and implementation.
Java allows using libraries code without any need of header files.
Following example showcases the same. Here we have used a class object before its declaration.
Example
public class Tester{ public static void main(String args[]) { Test t = new Test(); t.display(); } } class Test { public void display() { System.out.println("Test"); } }
Output
Test
- Related Articles
- What are forward declarations in C++?
- Why do we need generics in Java?
- Why do we need inner classes in Java?
- Why do we need a wrapper class in Java?
- Why do Java array declarations use curly brackets?
- Why do we need private methods in an interface in Java 9?
- Why do we need KDD?
- Why do we need Energy?
- Why do we need weakMaps in Javascript?
- Array Declarations in Java
- Why do we need Good Manners?
- Why do we need a Database
- When do we need Continuous Compounding?
- Why do we need Computer Networks?
- Why do we need shell scripting?

Advertisements