The this keyword is a reference variable that refers to the current object. There are the various uses of this keyword in Java. It can be used to refer to current class properties such as instance methods, variable, constructors, etc. It can also be passed as an argument into the methods or constructors. It can also be… Continue reading What is this keyword in java?
Month: March 2022
Why is the main method static?
Because the object is not required to call the static method. If we make the main method non-static, JVM will have to create its object first and then call main() method which will lead to the extra memory allocation.
What are the restrictions that are applied to the Java static methods?
Two main restrictions are applied to the static methods. The static method can not use non-static data member or call the non-static method directly. this and super cannot be used in static context as they are non-static.
What is the static method?
A static method belongs to the class rather than the object. There is no need to create the object to call the static methods. A static method can access and change the value of the static variable.
What is the static variable?
The static variable is used to refer to the common property of all objects (that is not unique for each object), e.g., The company name of employees, college name of students, etc. Static variable gets memory only once in the class area at the time of class loading. Using a static variable makes your program… Continue reading What is the static variable?
What is the purpose of a default constructor?
The purpose of the default constructor is to assign the default value to the objects. The java compiler creates a default constructor implicitly if there is no constructor in the class. Output: Explanation: In the above class, you are not creating any constructor, so compiler provides you a default constructor. Here 0 and null values are… Continue reading What is the purpose of a default constructor?
How many types of constructors are used in Java?
Based on the parameters passed in the constructors, there are two types of constructors in Java. Default Constructor: default constructor is the one which does not accept any value. The default constructor is mainly used to initialize the instance variable with the default values. It can also be used for performing some useful task on object… Continue reading How many types of constructors are used in Java?
What is the constructor?
The constructor can be defined as the special type of method that is used to initialize the state of an object. It is invoked when the class is instantiated, and the memory is allocated for the object. Every time, an object is created using the new keyword, the default constructor of the class is called. The name… Continue reading What is the constructor?
What will be the initial value of an object reference which is defined as an instance variable?
All object references are initialized to null in Java.
What is the difference b/w an object-oriented programming lang.. and object-based programming lang..?
There are the following basic differences between the object-oriented language and object-based language. Object-oriented languages follow all the concepts of OOPs whereas, the object-based language doesn’t follow all the concepts of OOPs like inheritance and polymorphism. Object-oriented languages do not have the inbuilt objects whereas Object-based languages have the inbuilt objects, for example, JavaScript has… Continue reading What is the difference b/w an object-oriented programming lang.. and object-based programming lang..?