varma

varma

54 Articles Published

Articles by varma

Page 6 of 6

Why can’t we override static methods in Java?

varma
varma
Updated on 30-Jul-2019 5K+ Views

Overloading is the mechanism of binding the method call with the method body dynamically based on the parameters passed to the method call.Static methods are bonded at compile time using static binding. Therefore, we cannot override static methods in Java.

Read More

How do I write method names in Java?

varma
varma
Updated on 30-Jul-2019 3K+ Views

While writing a method name we should follow the camel case i.e. first letter of the first word should be small and the first letters of the remaining (later) words should be capital. Example public class Test { public void sampleMethod() { System.out.println("This is sample method"); } public void demoMethod() { System.out.println("This is demo method"); } public static void main(String args[]) { Test obj = new Test(); obj.sample(); obj.demo(); } } Output This is sample method This is demo method

Read More

What is Is-a relationship in Java?

varma
varma
Updated on 30-Jul-2019 1K+ Views

IS-A is a way of saying: This object is a type of that object. Let us see how the extends keyword is used to achieve inheritance.Examplepublic class Animal { } public class Mammal extends Animal { } public class Reptile extends Animal { } public class Dog extends Mammal { }Now, based on the above example, in Object-Oriented terms, the following are true −Animal is the superclass of Mammal class.Animal is the superclass of Reptile class.Mammal and Reptile are subclasses of Animal class.Dog is the subclass of both Mammal and Animal classes.Example Live Democlass Animal { } class Mammal extends Animal ...

Read More

Are the private variables and private methods of a parent class inherited by the child class in Java?

varma
varma
Updated on 30-Jul-2019 989 Views

No, a child class can’t inherit private members of the parent class, it can inherit only protected, default, and public members of it. If you try it gives you a compile time error as: − Example class Super{ private int data = 30; public void display(){ System.out.println("Hello this is the method of the super class"); } } public class Sub extends Super{ public void greet(){ System.out.println("Hello this is the method of the sub class"); ...

Read More
Showing 51–54 of 54 articles
« Prev 1 2 3 4 5 6 Next »
Advertisements