vinay chaturvedi

Greenhorn
+ Follow
since Jan 16, 2012
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by vinay chaturvedi

You have to define the div method as below :



User defined Exception is always thrown using "throw" keyword.
8 years ago
Default constructor is the constructor that is inserted in a class by the compiler if the compiler doesn't find any constructor in the class at the time of compilation of the class. This default constructor inserted by the compiler is a no-argument constructor.

In the case when a user defines a no-argument constructor in a class then the compiler doesn't insert its default constructor in the class. Hence A default constructor is always a no-argument constructor but a no-argument constructor may or may not be a default constructor.
8 years ago


Arrays.sort(numbers);
//this is where the error happens
System.out.println(numbers[i]);



If you want to print the sorted array, then you have to iterate over the array.

See the below code :



You can not store the sorted array as the Array.sort() method returns void.
8 years ago

Gus Hayes wrote :
The multiply method is called with parameters 5 & 6 passed to it.



*First of all the multiply method is called with the PassObj object passed to it.

The point of :

is to assign the values p1 and p2 to instance variables n1 and n2.

When you are instantiating PassObj "PassObj obj1 = new PassObj(5,6);" the PassObj(int p1, int p2) constructor will be called and values will be assigned.

The constructor call is shown in bold in above line.
8 years ago
Thanks for the corrections Mike!!
8 years ago
Ordered means the order in which the elements are added in a collection is maintained.

For Ex : List is an ordered collection of objects.

Sorted means the elements added in to a collection will be added in their natural sorting order.

For Ex : SortedSet is a sorted collection of objects.

See the below code :



Output :

List values are : [C, B, A]
Set values are : [A, C, D]

**The List values are in the order in which they are added in to it.

**The Set values are automatically sorted.

8 years ago
The code looks fine. Please check if you have saved the java file with the name "Light .java". The error seems to be because of this only.
8 years ago
As your class is implementing Comparable interface it has to implement the compareTo() method.

The second compareTo() method is called on String variable. As you know String class also implements Comparable interface, hence it contains compareTo() method.

So the second compareTo() method that is called is of String class.

The compareTo method of String class compares the current title with the title value provided and returns an integer value (zero, negative or positive).

zero : both the values are equal.
negative : first value is less than second value
positive : first value is greater than second value.

*Note : compareTo method of Comparable is always based on natural sorting order.
8 years ago
You can use super as a keyword to call the super class methods in a sub-class.

For Ex : super.superClassMethod();

Or you can use super() to call the super class constructor.

For Ex :



8 years ago
A static nested class behaves as any other top-level class. A static nested class interacts with the instance members of its outer class (and other classes) just like any other top-level class.

Static nested classes are accessed using the enclosing outer class name:

"Outer.D"

For example, to create an object for the static nested class, use this syntax :

Outer.D nestedObject = new Outer.D();

For non-static nested classes you can create object as :

Outer.D nestedObject = new Outer().new D();

OR,

Outer outer = new Outer();

Outer.D nestedObject = outer.new D();

8 years ago
The java classes such as String, Number, StringBuffer, StringBuilder, Object, etc. are present in package "java.lang". In every java class this java.lang package is by default imported.
Hence all these classes are available in a class.
8 years ago
Yes in some cases the abstract class may or may not contain any abstract methods. For Ex. In the case of "HttpServlet" class. This class contains all implemented methods but still it is an abstract class.
There are the cases in which you don't want to implement an Interface because you have to define all the methods of the implemented interface. In such cases these abstract classes becomes useful as they already contain method implementations. So when you extend the abstract class you just have to override the method you need.
8 years ago
If you declare a method with a private modifier, then that method is private to that particular class. The child classes of that class cannot access that method.

In case of public modifier, methods in parent class with public modifiers are accessible in child classes.

Constructors are called whenever a new object is created for a class. Constructors can be private or public.

8 years ago