What will be the output of the following Java program.
// filename: Test2.java // main() function of this class uses Test1 which is declared later in // this file class Test2 { public static void main(String[] args) { Test1 t1 = new Test1(); t1.fun(5); } } class Test1 { void fun(int x) { System.out.println("fun() called: x = " + x); } }
Output:
fun() called: x = 5
The Java program compiles and runs fine. Note that Test1 and fun() don't seem to be declared before their use. Unlike C++, we tend to don’t want forward declarations in Java. Identifiers (class and technique names) square measure recognized mechanically from supply files. Similarly, library strategies square measure directly browse from the libraries, and there's no have to be compelled to produce header files with declarations. Java uses a naming theme wherever package and public category names should follow directory and file names severally. This naming theme permits the Java compiler to find library files.
Australia
UK
UAE
Singapore
Canada
New
Zealand
Malaysia
USA
India
South
Africa
Ireland
Saudi
Arab
Qatar
Kuwait
Hongkong
Copyright 2016-2023 www.programmingshark.com - All Rights Reserved.
Disclaimer : Any type of help and guidance service given by us is just for reference purpose. We never ask any of our clients to submit our solution guide as it is, anywhere.