Problem Questions
Problem 1 What is a Class?
Problem 2 What is state of an Object?
Problem 3 What is behavior of an Object?
Problem 4 What is the super class of every class in Java?
Problem 5 Explain about toString method ?
Problem 6 What is the use of equals method in Java ?
Problem 7 What are the important things to consider when implementing equals method?
Problem 8 What is the hashCode method used for in Java?
Problem 9 Explain inheritance with Examples.
Problem 10 What is Method Overloading?
Problem 11 What is Method Overriding?
Problem 12 Can super class reference variable can hold an object of sub class?
Problem 13 Is Multiple Inheritance allowed in Java?
Problem 14 What is an Interface ?
Problem 15 How do you define an Interface ?
Problem 16 How do you implement an interface ?
Problem 17 Can you explain a few tricky things about interfaces ?
Problem 18 Can you extend an interface ?
Problem 19 Can a class implements multiple interfaces ?
Problem 20 What is an Abstract Class ?
When do you use an Abstract Class ?
How do you define an Abstract Method ?
Compare Abstract Class vs Interfaces ?
Problem 21 What is a Constructor?
Problem 22 What is a Default Constructor?
Problem 23 Will this code compile?
Problem 24 How do you call a Super Class Constructor from a Constructor?
Problem 25 Will this code Compile?
Problem 26 What is the use of this()?
Problem 27 Can a constructor be called directly from a method?
Problem 28 Is a super class constructor called even when there is no explicit call from a sub class constructor ?
Problem 29 Difference between compile time and run time polymorphism - Link

Difference between compile time and run time polymorphism ?

Solution Link

Can we override static methods?

No, we cannot override static methods

because method overriding is based on dynamic binding at runtime and the static methods are bonded using static binding at compile time. So, we cannot override static methods. The calling of method depends upon the type of object that calls the static method.

What is a Class?

**Let’s look at an example:**

package com.rithus;

public class CricketScorer {
		//Instance Variables - constitute the state of an object
		private int score;

		//Behavior - all the methods that are part of the class
		//An object of this type has behavior based on the
		//methods four, six and getScore
		public void four(){
		score = score + 4;
		}

		public void six(){
		score = score + 6;
		}
	
		public int getScore() {
		return score;
		}

		**public static void main(String[] args) {
			CricketScorer scorer = new CricketScorer();
			scorer.six();
			//State of scorer is (score => 6)
			scorer.four();
			//State of scorer is (score => 10)
			System.out.println(scorer.getScore());
	}**

}

Class

A class is a Template. In above example, Class CricketScorer is the template 
for creating multipleobjects. A class defines state and behavior that an object 
can exhibit.

What is an Object?

An instance of a class. In the above example, we create an object using new 
CricketScorer(). The reference of the created object is stored in scorer 
variable. We can create multiple objects of the sameclass.

What is state of an Object?