Java Questions

Q:

Which is a reserved word in the java programming language?

A) Variable B) Identifier
C) Keyword D) Main
 
Answer & Explanation Answer: C) Keyword

Explanation:

Reserved words are words that cannot be used as object or variable names in a Java program because they're already used by the syntax of the Java programming language.

Java reserved words are keywords that are reserved by Java functions or other uses that cannot be used as identifiers (e.g., variable names, function names, class names).

If a reserved word was used as a variable you would get an error or unexpected result.

 

Examples : Int, Long, Abstract, Class, Break, Catch, Case, Public, Static, Void,...

 

 

Report Error

View Answer Report Error Discuss

1 2213
Q:

What is String Args in Java?

Answer

String Args (String []) is an array of parameters of type String.


In Java, 'args' contains the supplied command-line arguments as an array of String objects. In other words, if you run your program as 'java MyProgram Hello World' then 'args' will contain ["Hello", "World"]. When a java class is executed from the console, the main method is what is called.

Report Error

View answer Workspace Report Error Discuss

9 2211
Q:

Can a class be declared as protected?

Answer A class can't be declared as protected. only methods can be declared as protected.
Report Error

View answer Workspace Report Error Discuss

Subject: Java

0 2207
Q:

Can you access non static variable in static context ?

Answer

A static variable in Java belongs to its class and its value remains the same for all its instances. A static variable is initialized when the class is loaded by the JVM. If your code tries to access a non-static variable, without any instance, the compiler will complain, because those variables are not created yet and they are not associated with any instance.

Report Error

View answer Workspace Report Error Discuss

Subject: Java

0 2206
Q:

What are the basic interfaces of Java Collections Framework ?

Answer

Java Collections Framework provides a well designed set of interfaces and classes that support operations on a collections of objects. The most basic interfaces that reside in the Java Collections Framework are:


Collection, which represents a group of objects known as its elements.


Set, which is a collection that cannot contain duplicate elements.


List, which is an ordered collection and can contain duplicate elements.


Map, which is an object that maps keys to values and cannot contain duplicate keys.

Report Error

View answer Workspace Report Error Discuss

Subject: Java

1 2201
Q:

What is final method?

Answer

Final method is a method defined in the super class with final modifier.


We cannot overriding final method of super class in the sub class.


EX:


 Class Sample {


   final void funOne() {


   }


   void funTwo() {


   }


}


Class Sub extends Sample {


  void funOne() { // overriding is not allowed


  }


  viod funTwo() { //overriding is allowed


  }


}

Report Error

View answer Workspace Report Error Discuss

Subject: Java

0 2198
Q:

In a single virtual machine, the Java programming language passes arguments by

A) Refference B) Value
C) Both A and B D) None
 
Answer & Explanation Answer: B) Value

Explanation:

In single virtual machine,JVM passes arguments only by value.

Report Error

View Answer Report Error Discuss

Filed Under: Java

0 2188
Q:

What is the return type of the main() method?

Answer Main() method doesn't return anything hence declared void.
Report Error

View answer Workspace Report Error Discuss

Subject: Java

0 2174