Maruthi Krishna has Published 951 Articles

Can we declare main() method as private or protected or with no access modifier in java?

Maruthi Krishna

Maruthi Krishna

Updated on 29-Jun-2020 13:00:49

4K+ Views

Java provides various access specifiers namely private, public and protected etc...The Private modifier restricts the access of members from outside the class. A class and interface cannot be public.The Public access modifier can be associated with class, method, constructor, interface, etc. public can be accessed from any other class.The protected ... Read More

Can We declare main() method as Non-Static in java?

Maruthi Krishna

Maruthi Krishna

Updated on 29-Jun-2020 12:59:51

6K+ Views

The public static void main(String ar[]) method is the entry point of the execution in Java. When we run a .class file JVM searches for the main method and executes the contents of it line by line.You can write the main method in your program without the static modifier, the program ... Read More

Can we declare final variables without initialization in java?

Maruthi Krishna

Maruthi Krishna

Updated on 29-Jun-2020 12:57:54

4K+ 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 final it cannot be extended.Declaring final variable without initializationIf you declare ... Read More

How many ways are there to initialize a final variable in java?

Maruthi Krishna

Maruthi Krishna

Updated on 29-Jun-2020 12:56:07

3K+ 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 final it cannot be extended.Initializing a final variableOnce you declare a ... Read More

Why final variable doesn't require initialization in main method in java?

Maruthi Krishna

Maruthi Krishna

Updated on 29-Jun-2020 12:53:35

559 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 final it cannot be extended.Declaring final variable without initializationIf you declare ... Read More

Can we declare constructor as final in java?

Maruthi Krishna

Maruthi Krishna

Updated on 29-Jun-2020 12:51:54

3K+ Views

A constructor is used to initialize an object when it is created. It is syntactically similar to a method. The difference is that the constructors have the same name as their class and, have no return type.There is no need to invoke constructors explicitly these are automatically invoked at the ... Read More

What happens if we call "super()" in a constructor without extending any class, in java?

Maruthi Krishna

Maruthi Krishna

Updated on 29-Jun-2020 12:41:12

2K+ Views

A super keyword is a reference of the superclass object in Java. Using this, you can invoke the instance methods constructors and, variables, of a superclass.Calling the constructor of a superclassYou can call the constructor of a superclass from the subclass’s constructor.ExampleConsider the following example, it has two classes SuperClass class ... Read More

Can we call methods of the superclass from a static method in java?

Maruthi Krishna

Maruthi Krishna

Updated on 29-Jun-2020 12:38:24

3K+ Views

Inheritance can be defined as the process where one (parent/super) class acquires the properties (methods and fields) of another (child/sub). With the use of inheritance, the information is made manageable in a hierarchical order. The class which inherits the properties is known as a subclass and the class whose properties ... Read More

Can we call Superclass’s static method from subclass in Java?

Maruthi Krishna

Maruthi Krishna

Updated on 29-Jun-2020 12:37:42

2K+ Views

A static method is the one which you can call without instantiating the class. If you want to call a static method of the superclass, you can call it directly using the class name.Example Live Demopublic class Sample{    public static void display(){       System.out.println("This is the static method........"); ... Read More

Can we call a method on "this" keyword from a constructor in java?

Maruthi Krishna

Maruthi Krishna

Updated on 29-Jun-2020 12:31:21

5K+ Views

The “this ” keyword in Java is used as a reference to the current object, with in an instance method or a constructor. Using this you can refer the members of a class such as constructors, variables and methods.Calling a method using this keyword from a constructorYes, as mentioned we ... Read More

Advertisements