Can we overload main method?
Yes, we can have multiple methods with name “main” in a single class. However if we run the class, java run time environment will look for main method with syntax aspublic static void main(String args[])
.Can we have multiple public classes in a java source file?
We can’t have more than one public class in a single java source file. A single source file can have multiple classes that are not public.What is Java Package and which package is imported by default?
Java package is the mechanism to organize the java classes by grouping them. The grouping logic can be based on functionality or modules based. A java class fully classified name contains package and class name. For example,java.lang.Object
is the fully classified name ofObject
class that is part ofjava.lang
package.java.lang
package is imported by default and we don’t need to import any class from this package explicitly.What are access modifiers?
Java provides access control through public, private and protected access modifier keywords. When none of these are used, it’s called default access modifier.
A java class can only have public or default access modifier.What is final keyword?
final keyword is used with Class to make sure no other class can extend it, for example String class is final and we can’t extend it.We can use the final keyword with methods to make sure child classes can’t override it.final keyword can be used with variables to make sure that it can be assigned only once. However the state of the variable can be changed, for example, we can assign a final variable to an object only once but the object variables can change later on.Java interface variables are by default final and static.What is static keyword?
static keyword can be used with class level variables to make it global i.e all the objects will share the same variable.static keyword can be used with methods also. A static method can access only static variables of class and invoke only static methods of the class.What is finally and finalize in java?
finally block is used with try-catch to put the code that you want to get executed always, even if any exception is thrown by the try-catch block. finally block is mostly used to release resources created in the try block.finalize() is a special method in Object class that we can override in our classes. This method gets called by the garbage collector when the object is getting garbage collected. This method is usually overridden to release system resources when the object is garbage collected.
HB Education and Consulting Services Private Limited is a leading -Training and Certification Company in Chennai offering Corporate Training Programs and IT Education Courses in diversified areas. Since its inception in 2010, HB Educational Services have trained and certified many students and professionals. For more details, please whatsapp +91-9884987719 or +91-8939308896 or visit www.hbservices.in
Monday, October 29, 2018
Java Interview Questions?
Subscribe to:
Post Comments (Atom)
Which Python course is best for beginners?
Level Up Your Python Prowess: Newbie Ninjas: Don't fret, little grasshoppers! Courses like "Learn Python 3" on Codecade...
-
Network Diagram Template Powerpoint Network Diagram Template Powerpoint 0914 Complex Networking Ideas Network Diagram Template P...
-
What is the difference between public and private IP address? A public IP address is an IP address that can be accessed over th...
No comments:
Post a Comment