The document discusses inheritance in object-oriented programming and Java. It defines inheritance as a mechanism where a subclass acquires the properties and behaviors of its parent class. There are three types of inheritance in Java: single inheritance where a subclass extends one parent class; multilevel inheritance which is a chain of inheritance; and hierarchical inheritance where multiple subclasses can extend the same parent class. The document also discusses interfaces in Java which define behaviors but not implementations, allowing for multiple inheritance through interfaces.
The document discusses inheritance in Java programming. It defines inheritance as a mechanism that allows one class to inherit features like fields and methods from another class. There are three main types of inheritance discussed - single inheritance where one class inherits from another, multilevel inheritance where a class inherits from another inherited class, and hierarchical inheritance where multiple classes inherit from a single base class. The key concepts of superclass, subclass, method overriding and abstract classes are explained.
Inheritance allows classes to inherit properties and behaviors from parent classes in Java and C#. Both languages support simple, multilevel, and hierarchical inheritance through the use of extends and implements keywords. Java does not support multiple inheritance directly but allows classes to inherit from one parent class and implement multiple interfaces. Constructors and methods can be called or overridden in subclasses using the super and this keywords respectively.
Introduction of Object Oriented Programming Language using Java. .pptxPoonam60376
The slide contains the Introduction of Object Oriented Programming Language using Java. It covers basics of OOP, Inheritance,Polymorphism, Exception etc.
- Java uses classes and objects to organize code and data. A class defines the blueprint for an object and can contain attributes and methods.
- To create a class, use the "class" keyword followed by the class name. Objects are instances of classes and are created using the "new" keyword.
- The basic structure of a Java program includes creating a class, writing a main method with the public static void signature, and using print statements to output text. Command line arguments can be passed into the main method.
- Inheritance allows classes to inherit and extend the functionality of other classes. Subclasses inherit attributes and behaviors from their parent superclass. This supports code reuse and method overriding for polymorphism.
This document discusses Java inheritance including composition vs inheritance, inheritance definitions, types of inheritance (single, multilevel, hierarchical), why multiple inheritance is not supported, the super keyword and its uses, method overriding rules and examples. It defines inheritance as a parent-child relationship between classes that allows code and method reuse/overriding. Composition exhibits a "has-a" relationship while inheritance exhibits an "is-a" relationship. The super keyword can be used to access parent class members and call parent class methods/constructors. Method overriding provides a specific implementation of a method already in the parent class.
UNIT-2.pptx CS3391 Inheritance , types, packages and InterfacesSakkaravarthiS1
This document discusses various Java concepts including method overloading, objects as parameters, returning objects, static, nested and inner classes, inheritance basics and types, the super keyword, method overriding and dynamic method dispatch, abstract classes, final with inheritance, packages and interfaces. It provides examples and explanations of each concept.
Inheritance is a mechanism in Java that allows one class to acquire the properties (fields and methods) of another class. The class that inherits is called the subclass, and the class being inherited from is called the superclass. This allows code reuse and establishes an is-a relationship between classes. There are three main types of inheritance in Java: single, multilevel, and hierarchical. Method overriding and dynamic method dispatch allow subclasses to provide their own implementation of methods defined in the superclass.
The document discusses inheritance in Java. It defines key terminology like superclass, subclass, reusability and the extends keyword. It provides examples of single inheritance with an Employee and Programmer class, and multilevel inheritance with an Animal, Dog and BabyDog class. It also covers method overriding, where a subclass provides its own implementation of a method in the superclass. Dynamic method dispatch is explained, where the version of an overridden method that is executed depends on the object type, not the reference variable type. The document concludes with an overview of method overloading.
This document discusses object-oriented programming concepts in Java including inheritance, polymorphism, abstract classes, interfaces, and packages. It defines inheritance as a mechanism where one class acquires properties and behaviors of a parent class. Polymorphism is achieved through method overloading and overriding. Abstract classes can contain abstract and non-abstract methods while interfaces contain only abstract methods. Packages are used to categorize classes and interfaces to avoid naming collisions.
Inheritance in Java allows classes to inherit properties and behaviors from parent classes. This allows code reusability and method overriding to achieve runtime polymorphism. There are three types of inheritance in Java: single inheritance where a class inherits from one parent class, multilevel inheritance where a child class inherits from another child class, and hierarchical inheritance where multiple classes inherit from a single parent class.
The document discusses inheritance in Java. It defines inheritance as a process where one class acquires properties of another class. The class that inherits properties is called a subclass, and the class whose properties are inherited is called a superclass. In Java, a subclass can only inherit from one superclass (single inheritance). The extends keyword is used for inheritance. The document then discusses what can be done in subclasses, such as overriding and overloading methods, and polymorphism. It also covers abstract classes, interfaces, and casting objects.
Inheritance in Java beginner to advance with examples.pptxnaeemcse
Dive into the world of Java Inheritance and discover how it forms the backbone of robust and scalable code architecture. Learn how this powerful object-oriented programming concept allows you to effortlessly reuse and extend existing code, promoting a modular and maintainable design. Whether you're a novice or a seasoned developer, grasp the key principles of inheritance and elevate your Java programming skills. Join us on this journey to empower your code with the inheritance advantage, setting the stage for efficient development and enhanced software flexibility. Don't miss out on this essential building block for creating elegant and efficient Java applications!Unlock the potential of Java Inheritance with a concise exploration of single, multiple, multilevel, and hierarchical types. Discover how each type enhances code structure and flexibility. Elevate your Java skills by understanding the nuances of inheritance, optimizing code for efficiency and maintainability. Join us on this journey of code mastery and harness the diverse power of inheritance in your Java projects.
This presentation is ideal for a beginner of Java or someone who wants to brush up their Java Knowledge. It's simple to understand and well organized in a way most of the area in core Java has been covered.
Inheritance allows one class to acquire properties of another class. The subclass inherits from the superclass. The extends keyword is used to inherit properties from a superclass. Java supports single inheritance but not multiple inheritance to avoid complexity. The super keyword is used to refer to superclass members and call superclass constructors. Nested classes allow defining a class within another class. Inner classes can access private members of the outer class.
The document discusses object-oriented programming fundamentals including packages, access specifiers, the this keyword, encapsulation, inheritance, overriding, and polymorphism. A package organizes related classes and interfaces into namespaces. Access specifiers set access levels for classes, variables, methods, and constructors. The this keyword refers to the current object. Encapsulation hides implementation details by making fields private and providing public access methods. Inheritance allows a class to acquire properties of another class. Overriding defines a method with the same signature as a parent method. Polymorphism allows an object to take on multiple forms through method overloading and object references to child classes.
Jacob Murphy Australia - Excels In Optimizing Software ApplicationsJacob Murphy Australia
In the world of technology, Jacob Murphy Australia stands out as a Junior Software Engineer with a passion for innovation. Holding a Bachelor of Science in Computer Science from Columbia University, Jacob's forte lies in software engineering and object-oriented programming. As a Freelance Software Engineer, he excels in optimizing software applications to deliver exceptional user experiences and operational efficiency. Jacob thrives in collaborative environments, actively engaging in design and code reviews to ensure top-notch solutions. With a diverse skill set encompassing Java, C++, Python, and Agile methodologies, Jacob is poised to be a valuable asset to any software development team.
Ad
More Related Content
Similar to Basics to java programming and concepts of java (20)
Introduction of Object Oriented Programming Language using Java. .pptxPoonam60376
The slide contains the Introduction of Object Oriented Programming Language using Java. It covers basics of OOP, Inheritance,Polymorphism, Exception etc.
- Java uses classes and objects to organize code and data. A class defines the blueprint for an object and can contain attributes and methods.
- To create a class, use the "class" keyword followed by the class name. Objects are instances of classes and are created using the "new" keyword.
- The basic structure of a Java program includes creating a class, writing a main method with the public static void signature, and using print statements to output text. Command line arguments can be passed into the main method.
- Inheritance allows classes to inherit and extend the functionality of other classes. Subclasses inherit attributes and behaviors from their parent superclass. This supports code reuse and method overriding for polymorphism.
This document discusses Java inheritance including composition vs inheritance, inheritance definitions, types of inheritance (single, multilevel, hierarchical), why multiple inheritance is not supported, the super keyword and its uses, method overriding rules and examples. It defines inheritance as a parent-child relationship between classes that allows code and method reuse/overriding. Composition exhibits a "has-a" relationship while inheritance exhibits an "is-a" relationship. The super keyword can be used to access parent class members and call parent class methods/constructors. Method overriding provides a specific implementation of a method already in the parent class.
UNIT-2.pptx CS3391 Inheritance , types, packages and InterfacesSakkaravarthiS1
This document discusses various Java concepts including method overloading, objects as parameters, returning objects, static, nested and inner classes, inheritance basics and types, the super keyword, method overriding and dynamic method dispatch, abstract classes, final with inheritance, packages and interfaces. It provides examples and explanations of each concept.
Inheritance is a mechanism in Java that allows one class to acquire the properties (fields and methods) of another class. The class that inherits is called the subclass, and the class being inherited from is called the superclass. This allows code reuse and establishes an is-a relationship between classes. There are three main types of inheritance in Java: single, multilevel, and hierarchical. Method overriding and dynamic method dispatch allow subclasses to provide their own implementation of methods defined in the superclass.
The document discusses inheritance in Java. It defines key terminology like superclass, subclass, reusability and the extends keyword. It provides examples of single inheritance with an Employee and Programmer class, and multilevel inheritance with an Animal, Dog and BabyDog class. It also covers method overriding, where a subclass provides its own implementation of a method in the superclass. Dynamic method dispatch is explained, where the version of an overridden method that is executed depends on the object type, not the reference variable type. The document concludes with an overview of method overloading.
This document discusses object-oriented programming concepts in Java including inheritance, polymorphism, abstract classes, interfaces, and packages. It defines inheritance as a mechanism where one class acquires properties and behaviors of a parent class. Polymorphism is achieved through method overloading and overriding. Abstract classes can contain abstract and non-abstract methods while interfaces contain only abstract methods. Packages are used to categorize classes and interfaces to avoid naming collisions.
Inheritance in Java allows classes to inherit properties and behaviors from parent classes. This allows code reusability and method overriding to achieve runtime polymorphism. There are three types of inheritance in Java: single inheritance where a class inherits from one parent class, multilevel inheritance where a child class inherits from another child class, and hierarchical inheritance where multiple classes inherit from a single parent class.
The document discusses inheritance in Java. It defines inheritance as a process where one class acquires properties of another class. The class that inherits properties is called a subclass, and the class whose properties are inherited is called a superclass. In Java, a subclass can only inherit from one superclass (single inheritance). The extends keyword is used for inheritance. The document then discusses what can be done in subclasses, such as overriding and overloading methods, and polymorphism. It also covers abstract classes, interfaces, and casting objects.
Inheritance in Java beginner to advance with examples.pptxnaeemcse
Dive into the world of Java Inheritance and discover how it forms the backbone of robust and scalable code architecture. Learn how this powerful object-oriented programming concept allows you to effortlessly reuse and extend existing code, promoting a modular and maintainable design. Whether you're a novice or a seasoned developer, grasp the key principles of inheritance and elevate your Java programming skills. Join us on this journey to empower your code with the inheritance advantage, setting the stage for efficient development and enhanced software flexibility. Don't miss out on this essential building block for creating elegant and efficient Java applications!Unlock the potential of Java Inheritance with a concise exploration of single, multiple, multilevel, and hierarchical types. Discover how each type enhances code structure and flexibility. Elevate your Java skills by understanding the nuances of inheritance, optimizing code for efficiency and maintainability. Join us on this journey of code mastery and harness the diverse power of inheritance in your Java projects.
This presentation is ideal for a beginner of Java or someone who wants to brush up their Java Knowledge. It's simple to understand and well organized in a way most of the area in core Java has been covered.
Inheritance allows one class to acquire properties of another class. The subclass inherits from the superclass. The extends keyword is used to inherit properties from a superclass. Java supports single inheritance but not multiple inheritance to avoid complexity. The super keyword is used to refer to superclass members and call superclass constructors. Nested classes allow defining a class within another class. Inner classes can access private members of the outer class.
The document discusses object-oriented programming fundamentals including packages, access specifiers, the this keyword, encapsulation, inheritance, overriding, and polymorphism. A package organizes related classes and interfaces into namespaces. Access specifiers set access levels for classes, variables, methods, and constructors. The this keyword refers to the current object. Encapsulation hides implementation details by making fields private and providing public access methods. Inheritance allows a class to acquire properties of another class. Overriding defines a method with the same signature as a parent method. Polymorphism allows an object to take on multiple forms through method overloading and object references to child classes.
Jacob Murphy Australia - Excels In Optimizing Software ApplicationsJacob Murphy Australia
In the world of technology, Jacob Murphy Australia stands out as a Junior Software Engineer with a passion for innovation. Holding a Bachelor of Science in Computer Science from Columbia University, Jacob's forte lies in software engineering and object-oriented programming. As a Freelance Software Engineer, he excels in optimizing software applications to deliver exceptional user experiences and operational efficiency. Jacob thrives in collaborative environments, actively engaging in design and code reviews to ensure top-notch solutions. With a diverse skill set encompassing Java, C++, Python, and Agile methodologies, Jacob is poised to be a valuable asset to any software development team.
Design of Variable Depth Single-Span Post.pdfKamel Farid
Hunched Single Span Bridge: -
(HSSBs) have maximum depth at ends and minimum depth at midspan.
Used for long-span river crossings or highway overpasses when:
Aesthetically pleasing shape is required or
Vertical clearance needs to be maximized
The use of huge quantity of natural fine aggregate (NFA) and cement in civil construction work which have given rise to various ecological problems. The industrial waste like Blast furnace slag (GGBFS), fly ash, metakaolin, silica fume can be used as partly replacement for cement and manufactured sand obtained from crusher, was partly used as fine aggregate. In this work, MATLAB software model is developed using neural network toolbox to predict the flexural strength of concrete made by using pozzolanic materials and partly replacing natural fine aggregate (NFA) by Manufactured sand (MS). Flexural strength was experimentally calculated by casting beams specimens and results obtained from experiment were used to develop the artificial neural network (ANN) model. Total 131 results values were used to modeling formation and from that 30% data record was used for testing purpose and 70% data record was used for training purpose. 25 input materials properties were used to find the 28 days flexural strength of concrete obtained from partly replacing cement with pozzolans and partly replacing natural fine aggregate (NFA) by manufactured sand (MS). The results obtained from ANN model provides very strong accuracy to predict flexural strength of concrete obtained from partly replacing cement with pozzolans and natural fine aggregate (NFA) by manufactured sand.
How to Buy Snapchat Account A Step-by-Step Guide.pdfjamedlimmk
Scaling Growth with Multiple Snapchat Accounts: Strategies That Work
Operating multiple Snapchat accounts isn’t just a matter of logging in and out—it’s about crafting a scalable content strategy. Businesses and influencers who master this can turn Snapchat into a lead generation engine.
Key strategies include:
Content Calendars for Each Account – Plan distinct content buckets and themes per account to avoid duplication and maintain variety.
Geo-Based Content Segmentation – Use location-specific filters and cultural trends to speak directly to a region's audience.
Audience Mapping – Tailor messaging for niche segments: Gen Z, urban youth, gamers, shoppers, etc.
Metrics-Driven Storytelling – Use Snapchat Insights to monitor what type of content performs best per account.
Each account should have a unique identity but tie back to a central brand voice. This balance is crucial for brand consistency while leveraging the platform’s creative freedoms.
How Agencies and Creators Handle Bulk Snapchat Accounts
Digital agencies and creator networks often manage dozens—sometimes hundreds—of Snapchat accounts. The infrastructure to support this requires:
Dedicated teams for each cluster of accounts
Cloud-based mobile device management (MDM) systems
Permission-based account access for role clarity
Workflow automation tools (Slack, Trello, Notion) for content coordination
This is especially useful in verticals such as music promotion, event marketing, lifestyle brands, and political outreach, where each campaign needs targeted messaging from different handles.
The Legality and Risk Profile of Bulk Account Operations
If your aim is to operate or acquire multiple Snapchat accounts, understand the risk thresholds:
Personal Use (Low Risk) – One or two accounts for personal and creative projects
Business Use (Medium Risk) – Accounts with aligned goals, managed ethically
Automated Bulk Use (High Risk) – Accounts created en masse or used via bots are flagged quickly
Snapchat uses advanced machine learning detection for unusual behavior, including:
Fast switching between accounts from the same IP
Identical Snap stories across accounts
Rapid follower accumulation
Use of unverified devices or outdated OS versions
To stay compliant, use manual operations, vary behavior, and avoid gray-market account providers.
Smart Monetization Through Multi-Account Snapchat Strategies
With a multi-account setup, you can open doors to diversified monetization:
Affiliate Marketing – Niche accounts promoting targeted offers
Sponsored Content – Brands paying for story placement across multiple profiles
Product Launch Funnels – Segment users by interest and lead them to specific landing pages
Influencer Takeovers – Hosting creators across multiple themed accounts for event buzz
This turns your Snapchat network into a ROI-driven asset instead of a time sink.
Conclusion: Build an Ecosystem, Not Just Accounts
When approached correctly, multiple Snapchat accounts bec
This research is oriented towards exploring mode-wise corridor level travel-time estimation using Machine learning techniques such as Artificial Neural Network (ANN) and Support Vector Machine (SVM). Authors have considered buses (equipped with in-vehicle GPS) as the probe vehicles and attempted to calculate the travel-time of other modes such as cars along a stretch of arterial roads. The proposed study considers various influential factors that affect travel time such as road geometry, traffic parameters, location information from the GPS receiver and other spatiotemporal parameters that affect the travel-time. The study used a segment modeling method for segregating the data based on identified bus stop locations. A k-fold cross-validation technique was used for determining the optimum model parameters to be used in the ANN and SVM models. The developed models were tested on a study corridor of 59.48 km stretch in Mumbai, India. The data for this study were collected for a period of five days (Monday-Friday) during the morning peak period (from 8.00 am to 11.00 am). Evaluation scores such as MAPE (mean absolute percentage error), MAD (mean absolute deviation) and RMSE (root mean square error) were used for testing the performance of the models. The MAPE values for ANN and SVM models are 11.65 and 10.78 respectively. The developed model is further statistically validated using the Kolmogorov-Smirnov test. The results obtained from these tests proved that the proposed model is statistically valid.
The TRB AJE35 RIIM Coordination and Collaboration Subcommittee has organized a series of webinars focused on building coordination, collaboration, and cooperation across multiple groups. All webinars have been recorded and copies of the recording, transcripts, and slides are below. These resources are open-access following creative commons licensing agreements. The files may be found, organized by webinar date, below. The committee co-chairs would welcome any suggestions for future webinars. The support of the AASHTO RAC Coordination and Collaboration Task Force, the Council of University Transportation Centers, and AUTRI’s Alabama Transportation Assistance Program is gratefully acknowledged.
This webinar overviews proven methods for collaborating with USDOT University Transportation Centers (UTCs), emphasizing state departments of transportation and other stakeholders. It will cover partnerships at all UTC stages, from the Notice of Funding Opportunity (NOFO) release through proposal development, research and implementation. Successful USDOT UTC research, education, workforce development, and technology transfer best practices will be highlighted. Dr. Larry Rilett, Director of the Auburn University Transportation Research Institute will moderate.
For more information, visit: https://aub.ie/trbwebinars
Efficient Algorithms for Isogeny Computation on Hyperelliptic Curves: Their A...IJCNCJournal
We present efficient algorithms for computing isogenies between hyperelliptic curves, leveraging higher genus curves to enhance cryptographic protocols in the post-quantum context. Our algorithms reduce the computational complexity of isogeny computations from O(g4) to O(g3) operations for genus 2 curves, achieving significant efficiency gains over traditional elliptic curve methods. Detailed pseudocode and comprehensive complexity analyses demonstrate these improvements both theoretically and empirically. Additionally, we provide a thorough security analysis, including proofs of resistance to quantum attacks such as Shor's and Grover's algorithms. Our findings establish hyperelliptic isogeny-based cryptography as a promising candidate for secure and efficient post-quantum cryptographic systems.
Dear SICPA Team,
Please find attached a document outlining my professional background and experience.
I remain at your disposal should you have any questions or require further information.
Best regards,
Fabien Keller
This slide deck presents a detailed overview of the 2025 survey paper titled “A Survey of Personalized Large Language Models” by Liu et al. It explores how foundation models like GPT and LLaMA can be personalized to better reflect user-specific needs, preferences, and behaviors.
The presentation is structured around a 3-level taxonomy introduced in the paper:
Input-Level Personalization (e.g., user-profile prompting, memory retrieval)
Model-Level Personalization (e.g., LoRA, PEFT, adapters)
Objective-Level Personalization (e.g., RLHF, preference alignment)
2. Inheritance in Java
* Inheritance in Java is a mechanism in which one object acquires all the
properties and behaviors of a parent object. It is an important part of
OOPs(Object Oriented programming system).
* The idea behind inheritance in Java is that you can create new classes
that are built upon existing classes.
* When you inherit from an existing class, you can reuse methods and
fields of the parent class.
*Moreover, you can add new methods and fields in your current class
also.Inheritance represents the IS-A relationship which is also known as
a parent-child relationship
3. Why use inheritance in java
o 1.For Method Overriding
---→(so runtime polymorphism can be achieved).
2. For Code Reusability.
Terms used in Inheritance
Class: A class is a group of objects which have common properties. It is a
template or blueprint from which objects are created.
Sub Class/Child Class: Subclass is a class which inherits the other class. It is also
called a derived class, extended class, or child class.
4. Super Class/Parent Class: Superclass is the class from where a subclass
inherits the features. It is also called a base class or a parent class.
Reusability: As the name specifies, reusability is a mechanism which
facilitates you to reuse the fields and methods of the existing class when
you create a new class. You can use the same fields and methods already
defined in the previous class.
class Subclass-name extends Superclass-name
{
//methods and fields
}
Note: The extends keyword indicates that you are making a new class that
derives from an existing class. The meaning of "extends" is to increase the
functionality
5. class Employee{
float salary=40000;
}
class Programmer extends Employee{
int bonus=10000;
public static void main(String args[]){
Programmer p=new Programmer();
System.out.println("Programmer salary is:"+p.salary);
System.out.println("Bonus of Programmer is:"+p.bonus);
}
}
Programmer is the subclass and Employee is the superclass. The
relationship between the two classes is Programmer IS-A Employee. It
means that Programmer is a type of Employee.
6. Types of inheritance in java
On the basis of class, there can be three types of inheritance in java: single,
multilevel and hierarchical.
In java programming, multiple and hybrid inheritance is supported through
interface only. We will learn about interfaces later.
9. Single Inheritance Example
When a class inherits another class, it is known as a single inheritance.
class Animal{
void eat(){System.out.println("eating...");}
}
class Dog extends Animal{
void bark(){System.out.println("barking...");}
}
class TestInheritance{
public static void main(String args[]){
Dog d=new Dog();
d.bark();
d.eat();
}}
10. Multilevel Inheritance Example
When there is a chain of inheritance, it is known as multilevel inheritance
class Animal{
void eat(){System.out.println("eating...");}
}
class Dog extends Animal{
void bark(){System.out.println("barking...");}
}
class BabyDog extends Dog{
void weep(){System.out.println("weeping...");}
}
class TestInheritance2{
public static void main(String args[]){
BabyDog d=new BabyDog();
d.weep();
d.bark();
d.eat();
}}
11. Hierarchical Inheritance Example
When two or more classes inherits a single class, it is known as hierarchical
inheritance. class Animal{
void eat(){System.out.println("eating...");}
}
class Dog extends Animal{
void bark(){System.out.println("barking...");}
}
class Cat extends Animal{
void meow(){System.out.println("meowing...");}
}
class TestInheritance3{
public static void main(String args[]){
Cat c=new Cat();
c.meow();
c.eat();
//c.bark();//C.T.Error
}}
12. super key word
The super keyword in Java is a reference variable which is used to refer
immediate parent class object.
Usage of Java super Keyword
* super can be used to refer immediate parent class instance variable.
* super can be used to invoke immediate parent class method.
* super() can be used to invoke immediate parent class constructor.
13. class Animal {
public void move() {
System.out.println("Animals
can move");
}
public void eat()
{
System.out.println(" Animals
Will eat.");
}
}
class Dog extends Animal {
public void move() {
super.move(); // invokes the super class
method
System.out.println("Dogs can walk and run");
super.eat();
}
}
public class TestDog {
public static void main(String args[]) {
Dog d=new Dog();
d.move();
Animal obj = new Dog(); // Animal reference
but Dog object
obj.move(); // runs the method in Dog class
}
}
14. Preventing inheritance
While one of Java's strengths is the concept of inheritance, in which one class
can derive from another, sometimes it's desirable to prevent inheritance by
another class. To prevent inheritance, use the keyword "final" when creating
the class.
Why Prevent Inheritance?
The main reason to prevent inheritance is to make sure the way a class behaves
is not corrupted by a subclass.
15. public final class Account
{
statements
}
Suppose we have a class Account and a subclass that extends it,
OverdraftAccount. Class Account has a method getBalance()
This means that the Account class cannot be a superclass, and the OverdraftAccount class can
no longer be its subclass.
Sometimes, you may wish to limit only certain behaviors of a superclass to avoid corruption
by a subclass. For example, OverdraftAccount still could be a subclass of Account, but it should
be prevented from overriding the getBalance() method.
16. public class Account {
private double balance;
public final double getBalance()
{
return this.balance;
}
}
final is a non-access modifier for Java elements. The final modifier is used for
finalizing the implementations of classes, methods, and variables.
17. What are ways to Prevent Inheritance in Java Programming?
There are 2 ways to stop or prevent inheritance in Java programming.
By using final keyword with a class orBy using a private constructor in a class.
Final Keyword In Java
The final keyword in java is used to restrict the user. The java final keyword can
be used in many context. Final can be:
1. variable
2. method
3. class
18. The final keyword can be applied with the variables, a final variable that have
no value it is called blank final variable or uninitialized final variable. It can be
initialized in the constructor only. The blank final variable can be static also
which will be initialized in the static block only.
Java final variable
If you make any variable as final, you cannot change the value of final variable(It
will be constant)
19. class Bike9{
final int speedlimit=90;//final variable
void run(){
speedlimit=400;
}
public static void main(String args[]){
Bike9 obj=new Bike9();
obj.run();
}
}
63.151/Bike9.java:4: error: cannot assign a value to final variable
speedlimit
speedlimit=400;
^
1 error
20. Java final method
If you make any method as final, you cannot override it.
class Bike{
final void run(){System.out.println("running");}
}
class Honda extends Bike{
void run(){System.out.println("running safely with 100kmph");}
public static void main(String args[]){
Honda honda= new Honda();
honda.run();
}
}
Compile by: javac Honda.java
63.151/Honda.java:6: error: run() in Honda cannot override run() in Bike with 100kmph");}
^
overridden method is final
1 error
21. Java final class
If you make any class as final, you cannot extend it.
final class Bike{}
class Honda1 extends Bike{
void run(){System.out.println("running safely with 100kmph");}
public static void main(String args[]){
Honda1 honda= new Honda1();
honda.run();
}
}
Compile by: javac Honda1.java
3.133/Honda1.java:3: error: cannot inherit from final Bike class Honda1
extends Bike{}
22. Polymorphism
Polymorphism is briefly described as “one interface, many
implementations”.
Polymorphism in Java is a concept by which we can perform a single action
in different ways.
1. Compile time polymorphism
2. Run time polymorphism
Compile time polymorphism is method overloading whereas Runtime time
polymorphism is done using inheritance and interface.
23. Method Overriding in Java
If subclass (child class) has the same method as declared in the parent class, it
is known as method overriding in Java.
Rules for Java Method Overriding
1.The method must have the same name as in the parent class
2.The method must have the same parameter as in the parent class.
3.There must be an IS-A relationship (inheritance).
24. class Vehicle
{
void run(){
System.out.println("Vehicle is running");
}
}
class Bike2 extends Vehicle{
void run()
{
System.out.println("Bike is running safely");
}
public static void main(String args[]){
Bike2 obj = new Bike2();//creating object
obj.run();//calling method
} } OUT PUT: Bike is running safely
25. In Java, runtime polymorphism or dynamic method dispatch is a process in
which a call to an overridden method is resolved at runtime rather than at
compile-time. In this process, an overridden method is called through the
reference variable of a superclass.
class Car {
void run()
{ System.out.println(“car is running”); }
}
class Audi extends Car {
void run()
{ System.out.prinltn(“Audi is running safely with
100km”); }
public static void main(String args[])
{
Car b= new Audi(); //upcasting
b.run();
} }
Since method invocation is
determined by the JVM not
compiler, it is known as
runtime polymorphism.
26. class Bank{
float getRateOfInterest(){return 0;}
}
class SBI extends Bank{
float getRateOfInterest(){return 8.4f;}
}
class ICICI extends Bank{
float getRateOfInterest(){return 7.3f;}
}
class AXIS extends Bank{
float getRateOfInterest(){return 9.7f;}
}
class TestPolymorphism{
public static void main(String args[]){
Bank b;
b=new SBI();
System.out.println("SBI Rate of Interest:
"+b.getRateOfInterest());
b=new ICICI();
System.out.println("ICICI Rate of Interest:
"+b.getRateOfInterest());
b=new AXIS();
System.out.println("AXIS Rate of Interest:
"+b.getRateOfInterest());
}
}
27. Java Abstract Class and Abstract Methods
A class which is declared with the abstract keyword is known as an abstract
class in Java. It can have abstract (method with out body) and non-abstract
methods (method with the body).
Abstraction in Java
Abstraction is a process of hiding the implementation details and showing only
functionality to the user.
There are two ways to achieve abstraction in java
1.Abstract class (0 to 100%)
2.Interface (100%)
28. Abstract class in Java
A class which is declared as abstract is known as an abstract class. It can have
abstract and non-abstract methods. It needs to be extended and its method
implemented. It cannot be instantiated.
Points to Remember
•An abstract class must be declared with an abstract keyword.
•It can have abstract and non-abstract methods.
•It cannot be instantiated.
•It can have constructors and static methods also.
•It can have final methods which will force the subclass not to change
the body of the method.
1.abstract class A{}
29. Abstract Method in Java
A method which is declared as abstract and does not have implementation is
known as an abstract method.
1.abstract void printStatus();//no method body and abstract
abstract class Bike{
abstract void run();
}
class Honda4 extends Bike{
void run(){System.out.println("running safely");}
public static void main(String args[]){
Bike obj = new Honda4();
obj.run();
}
} OUT PUT : running safely
30. abstract class Shape{
abstract void draw();
}
//In real scenario, implementation is provided by others i.e. unknown by end user
class Rectangle extends Shape{
void draw(){System.out.println("drawing rectangle");}
}
class Circle1 extends Shape{
void draw(){System.out.println("drawing circle");}
}
//In real scenario, method is called by programmer or user
class TestAbstraction1{
public static void main(String args[]){
Shape s=new Circle1
s.draw();
}
} output: drawing circle
31. Abstract class having constructor, data member and
methods
abstract class Bike{
Bike(){System.out.println("bike is created");}
abstract void run();
void changeGear(){System.out.println("gear changed");}
}
class Honda extends Bike{
void run(){System.out.println("running safely..");}
}
class TestAbstraction2{
public static void main(String args[]){
Bike obj = new Honda();
obj.run();
obj.changeGear();
}
}
bike is created
running safely..
gear changed
32. Interface
An interface in Java is a blueprint of a class. It has static constants and
abstract methods.
An interface in Java is similar to class. It is a collection of abstract methods.
The interface in Java is a mechanism to achieve abstraction. There can be only
abstract methods in the Java interface, not method body. It is used to achieve
abstraction and multiple inheritance in Java.
Java Interface also represents the IS-A relationship.
It cannot be instantiated just like the abstract class.
33. A class implements an interface, thereby inheriting the abstract methods of the interface.
Writing an interface is similar to writing a class. But a class describes the attributes and
behaviors of an object. And an interface contains behaviors that a class implements.
Why use Java interface?
1) It is used to achieve abstraction.
2) By interface, we can support the functionality of multiple inheritance.
34. How to declare an interface?
An interface is declared by using the interface keyword. It provides total
abstraction; means all the methods in an interface are declared with the empty
body, and all the fields are public, static and final by default. A class that
implements an interface must implement all the methods declared in the
interface.
interface <interface_name>
{
// declare constant fields
// declare methods that abstract
// by default.
}
35. The relationship between classes and interfaces
A class extends another class, an interface extends another interface, but
a class implements an interface.
36. interface inter
{
int a=10,b=20;
public void add();
}
class c1 implements inter
{
public void add()
{
int sum=a+b;
System.out.println("Sum of numbers is:" +sum);
}
public static void main(String[] srgs)
{
c1 obj= new c1();
obj.add();
}
} output: Sum of numbers is: 30
37. interface Drawable{
void draw();
}
class Rectangle implements Drawable{
public void draw(){System.out.println("drawing rectangle");}
}
class Circle implements Drawable{
public void draw(){System.out.println("drawing circle");}
}
class TestInterface1{
public static void main(String args[]){
Drawable d=new Circle();
d.draw();
Drawable d1=new Rectangle();
d1.draw();
}} output: drawing circle
drawing rectangle
38. Multiple inheritance in Java by interface
If a class implements multiple interfaces, or an interface extends multiple
interfaces, it is known as multiple inheritance.
39. interface inter
{
int a=10,b=20;
public abstract void add();
}
interface inter1
{
int c=20,d=10;
public abstract void sub();
}
class c1 implements inter,inter1
{
public void add()
{
int sum=a+b;
System.out.println(" Sum of numbers
is :" +sum);
}
public void sub()
{
int r=c-d;
System.out.println(" Difference of numbers
is :" +r);
}
public static void main(String[] args)
{
c1 obj=new c1();
obj.add();
obj.sub();
}
} Output: Sum of numbers is : 30
Difference of numbers is: 10
40. Interface inheritance
A class implements an interface, but one interface extends another
interface. interface Printable{
void print();
}
interface Showable extends Printable{
void show();
}
class TestInterface4 implements Showable{
public void print(){System.out.println("Hello");}
public void show(){System.out.println("Welcome");}
public static void main(String args[]){
TestInterface4 obj = new TestInterface4();
obj.print();
obj.show();
} Out put : Hello
} Welcome
41. Java Nested Interface
An interface, i.e., declared within another interface or class, is known as a nested
interface. The nested interfaces are used to group related interfaces so that they
can be easy to maintain.
Points to remember
•The nested interface must be public if it is declared inside the interface, but it
can have any access modifier if declared within the class.
•Nested interfaces are declared static
43. Example of nested interface which is declared within the interface
interface Showable
{
void show();
interface Message
{
void msg();
}
}
class c1 implements Showable.Message
{
public void msg()
{
System.out.println("Hello nested interface");
}
public void show()
{
System.out.println("Welcome to nested interface");
}
public static void main(String args[])
{
c1 obj1=new c1();
obj1.msg();
obj1.show();
}
}
Output: Hello nested interface
Welcome to nested interface
44. Example of nested interface which is declared within the class
class A
{
interface Message
{
void msg();
void show();
}
}
class inter implements A.Message
{
public void msg()
{
System.out.println("Hello nested interface");
}
public void show()
{
System.out.println(" Welcome to nested interface");
}
public static void main(String args[]){
inter obj1=new inter();
obj1.show();
obj1.msg();
}
}
Output: Welcome to nested interface
Hello nested interface
45. Java Default Methods
Java provides a facility to create default methods inside the interface. Methods
which are defined inside the interface and tagged with default are known as default
methods. These methods are non-abstract methods.
interface add
{
public void addition();
default void addition1()
{ int a=1,b=2,c;
c=a+b;
System.out.println(c);
}
static void sub()
{
int l=20,m=10,n;
n=l-m;
System.out.println(n);
}
}
class c1 implements add{
public void addition()
{
int i=1,j=4,k;
k=i+j;
System.out.println(k); }
public static void main(String[] args)
{ add obj=new c1();
obj.addition();
obj.addition1();
add.sub();
}
} output:5
3
10
46. Difference between abstract class and interface
Abstract class Interface
1) Abstract class can have abstract and non-abstract methods. Interface can have only abstract methods. Since Java 8, it can have default
and static methods also.
2) Abstract class doesn't support multiple inheritance. Interface supports multiple inheritance.
3) Abstract class can have final, non-final, static and non-static
variables.
Interface has only static and final variables.
4) Abstract class can provide the implementation of interface. Interface can't provide the implementation of abstract class.
5) The abstract keyword is used to declare abstract class. The interface keyword is used to declare interface.
6) An abstract class can extend another Java class and implement
multiple Java interfaces.
An interface can extend another Java interface only.
7) An abstract class can be extended using keyword "extends". An interface can be implemented using keyword "implements".
8) A Java abstract class can have class members like private,
protected, etc.
Members of a Java interface are public by default.
9)Example:public abstract clasShape{
public abstract void draw();
}
Example:
public interface Drawable{
void draw();
}
47. Java Package
A java package is a group of similar types of classes, interfaces and sub-
packages.
Package in java can be categorized in two form, built-in package and user-
defined package.
There are many built-in packages such as java, lang, awt, javax, swing, net, io,
util, sql etc.
Advantage of Java Package
1) Java package is used to categorize the classes and interfaces so that they can
be easily maintained.
2) Java package provides access protection.
3) Java package removes naming collision.
48. The package keyword is used to create a package in java.
//save as Simple.java
package mypack;
public class Simple{
public static void main(String args[]){
System.out.println("Welcome to package");
}
}
49. 1. Core Packages: Core Packages are predefined
packages given by Sun MicroSystems which begin with
“java”.
2. Extended Packages: Extended packages are also
predefined packages given by Sun Microsystems which
begin with “javax”.
3. Third-Party Packages: Third-Party Packages are also
predefined packages that are given by some other
companies as a part of Java Software.
Example:oracle.jdbc, com.mysql, etc
50. User-Defined Packages in Java
In Java, we can also create user-defined packages according to our
requirements. To create the user-defined packages we have to use a java
keyword called “package.
51. Rules:
1. While writing the package name we can specify packages in any number of
levels but specifying one level is mandatory.
2. The package statement must be written as the first executable statement in
the program.
3. We can write at most one package statement in the program
package Demo;
public class PackageDemo {
public static void main(String args[]) {
System.out.println("Have a Nice
Day...!!!");
}
}
52. How to access package from another package?
There are three ways to access the package from outside the package.
1)import package.*;
2)import package.classname;
3)fully qualified name.
1) Using packagename.*
If you use package.* then all the classes and interfaces of this package will be
accessible but not subpackages.
The import keyword is used to make the classes and interface of another
package accessible to the current package.
53. //save by A.java
package pack;
public class A{
public void msg(){System.out.println("Hello");}
}
//save by B.java
package mypack;
import pack.*;
class B{
public static void main(String args[]){
A obj = new A();
obj.msg();
}
}
54. 2) Using packagename.classname
If you import package.classname then only declared class of this package will
be accessible.
//save by A.java
package pack;
public class A{
public void msg(){System.out.println("Hello");}
}
//save by B.java
package mypack;
import pack.A;
class B{
public static void main(String args[]){
A obj = new A();
obj.msg();
}
}
55. 3) Using fully qualified name
If you use fully qualified name then only declared class of this package will be
accessible. Now there is no need to import. But you need to use fully qualified
name every time when you are accessing the class or interface.
//save by A.java
package pack;
public class A{
public void msg(){System.out.println("Hello");}
}
//save by B.java
package mypack;
class B{
public static void main(String args[]){
pack.A obj = new pack.A();//using fully qualified name
obj.msg();
}
}
57. Subpackage in java
Package inside the package is called the subpackage. It should be created to
categorize the package further.
package pack.package;
class Simple{
public static void main(String args[]){
System.out.println("Hello subpackage");
}
}