Java Programs on Classes and Objects

Java Programming Examples - Classes and Objects

Java is an object-oriented programming language that focuses on classes, objects, and their methods and attributes. In Java, a class is a template or blueprint that is used to create objects. The class declaration component declares the class name as well as additional attributes like modifiers, class keywords, super classes, interfaces, and so on. An object is a member or instance of a Java class. Each object has its own identity, behavior, and state.

The following section contains various Java programs on classes, objects, methods, variables, method overloading, constructor, and superclasses. Each sample program includes a program description, Java code, and program output. All examples have been compiled and tested on Windows and Linux systems.

Here is the listing of Java programming examples on Classes and Objects:

  1. Java Programs on Classes
  2. Java Programs on Objects
  3. Java Programs on Methods
  4. Java Programs on Method Overloading
  5. Java Programs on Constructor
  6. Java Programs on Super Class
  7. Java Programs on Variables

1. Java Programs on Classes

Program Description
Abstract Class Features in Java Java Program to Illustrate Use of All Features of Abstract Class
Abstract Class and Method in Java Java Program to Illustrates Use of Abstract Class and Method
Instance Inner Class in Java Java Program to Illustrates Use of Instance Inner Class
Static Inner Class in Java Java Program to Illustrates Use of Static Inner Class
Object Reference from Inner Class in Java Java Program to Illustrates Use of Referencing the Object from Inner Class
Create Outer Class BankAcct & Inner Class Interest in Java Java Program to Create Outer Class Bank Account and the Inner Class Interest in it
Shape Interface using Circle and Rectangle Class in Java Java Program to Implement Shape Interface using Circle and Rectangle Class

advertisement
advertisement

2. Java Programs on Objects

Program Description
Count No of Objects Created for Class in Java Java Program to Count Number of Objects Created for Class
Passing and Returning Objects in Java Java Program to Implement the Passing and Returning Objects
Swap Objects using Swap() Method in Java Java Program to Swap Objects using Swap() Method

3. Java Programs on Methods

Program Description
Java Class Methods Java Program to Illustrate Use of Methods in a Class
Create Method without Parameters & with Return Type in Java Java Program to Create a Method without Parameters and with Return Type
Create Method without Parameters & Return Type in Java Java Program to Create a Method without Parameters and Return Type
Create Method with 2 Parameters & without Return Type in Java Java Program to Create a Method with 2 Parameters and without Return Type
HashCode() Method in Java Java Program to Illustrate the Use of HashCode() Method
Final Keyword in Java Java Program to Illustrate Use of Final Keyword

4. Java Programs on Method Overloading

Program Description
Arithmetic Operations using Method Overloading in Java Java Program to Find Arithmetic Sum by Passing Argument Using Method Overloading
Find Area of Shapes using Method Overloading in Java Java Program to Find Area of Square, Rectangle and Circle using Method Overloading
Nesting of Methods in Java Java Program to Show the Nesting of Methods

5. Java Programs on Constructor

Program Description
Constructor in Java Java Program to Illustrate Use of Constructor
Constructor Chaining in Java Java Program to Illustrates Use of Chaining Constructor
Create Object using Constructor in Java Java Program to Create an Object for Class and Assign Value in the Object using Constructor
String Constructor in Java String Constructor Program in Java
Super Class Constructor in Java Java Program to Allocate and Initialize Super Class Members using Constructor

6. Java Programs on Super Class

Program Description
Default Constructor in Java Java Program to Show the Availability of Default Constructor of the Super Class to the Sub Class by Default
Access Super Class Method and Instance Variable Using Super Keyword in Java Java Program to Access Super Class Method and Instance Variable Using Super Keyword
Access Super Class Method & Instance Variable without Super Keyword in Java Java Program to Access Super Class Method and Instance Variable without Super Keyword
Parameterized Constructor in Java Parameterized Constructor Program using super() in Java

7. Java Programs on Variables

Program Description
Check Accessibility of Static & Non-Static Variables by Static Method in Java Java Program to Check the Accessibility of Static and Non-Static Variable by a Static Method
Instance Variable in Java Java Program to Demonstrate Usage of an Instance Variable in the Test Class
Static Variable in Java Java Program to Demonstrate Usage of a Static Variable in the Test Class
Static Block or Static Method in Java Java Program to Check Whether Which One is Executed First, Static Block or the Static Method
Byte Addition using Type Casting in Java Java Program to Calculate Sum of Two Byte Values using Type Casting

advertisement
advertisement
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.