What is blank or uninitialized final variable in Java?

Ankitha Reddy
Published on 22-Apr-2018 20:47:52
No. It is not allowed in Java. The compiler will fail the compilation throwing error that the blank final field may not have been initialized.

Why use instance initializer block in Java?

Nikitha N
Published on 23-Apr-2018 11:45:19
instance initializer block is similar to a constructor. It is called once for each object and can be used to set initial values for instance variables. See the example below.Live Demopublic class Tester {    public int a;    { a = 10; }    public static void main(String[] args) ... Read More

What are the three usages of the super keyword in Java?

V Jyothi
Published on 23-Apr-2018 09:43:51
super variable refers immediate parent class instance.super variable can invoke immediate parent class method.super() acts as immediate parent class constructor and should be the first line in child class constructor.

What is covariant return type in Java?

Abhinanda Shri
Published on 22-Apr-2018 20:52:09
Covariant return type refers to return type of an overriding method. It allows to narrow down return type of an overridden method without any need to cast the type or check the return type. Covariant return type works only for non-primitive return types.From Java 5 onwards, we can override a ... Read More

Can we override the static method in Java?

Syed Javed
Published on 22-Apr-2018 20:54:44
Yes! We can override the static method easily in Java. See the example below.ExampleLive Demopublic class Tester {    public static void main(String[] args) {       display();       display("World!!");    }      private static void display(){       System.out.println("Hello!");    }      private ... Read More

Why use aggregation in Java?

Abhinanda Shri
Published on 22-Apr-2018 20:56:36
AggregationWhen an object A contains a reference to another object B or we can say Object A has a HAS-A relationship with Object B, then it is termed as Aggregation.Aggregation helps in reusing the code. Object B can have utility methods and which can be utilized by multiple objects. Whichever ... Read More

What are the 6 ways to use this keyword in Java?

Priya Pallavi
Published on 23-Apr-2018 07:28:18
this can be used to get the current object.this can be used to invoke current object's method.this() can be used to invoke current class constructorthis can be passed as a parameter to a method call.this can be passed as a parameter to a constructor.this can be used to return the ... Read More

Can we create a program without a main method in Java?

Syed Javed
Published on 23-Apr-2018 09:41:50
No. For Java based application, JVM will complain about missing main method.

Java constructor return a value but, what?

Priya Pallavi
Published on 23-Apr-2018 07:24:33
No. Java constructor cannot return a value. If required, just create a method which calls the required constructor and returns the required value. See the example below.public class Tester {    public Tester(){}    public static Tester getInstance(){       Tester tester = new Tester();        return ... Read More

Can we overload Java main method?

Syed Javed
Published on 23-Apr-2018 07:19:25
Yes, we can overload the main method of Java. But JVM will only call the default main method only. See the example below.ExampleLive Demopublic class Tester {    public static void main(String args[]) {      System.out.println("Default Main");      }      public static void main(String args) {   ... Read More
Advertisements