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.
Classes and objects are fundamental concepts in object-oriented programming. A class defines common properties and behaviors of objects through fields and methods. An object is an instance of a class that represents a real-world entity with state (fields) and behavior (methods). Classes can inherit properties and behaviors from superclasses and implement interfaces. Objects are created from classes using constructors.
The document discusses Java packages and interfaces. It provides details about:
- What packages are and how they are used to prevent naming conflicts and organize classes.
- How to define a user-defined package with an example.
- What interfaces are and how they allow for multiple inheritance by implementing multiple interfaces.
- Examples of defining and implementing interfaces.
The document discusses Java packages and interfaces. It provides details about:
1) Packages in Java are used to group related classes and interfaces to prevent naming conflicts, make classes easier to find, and control access levels. Packages can contain subpackages.
2) Interfaces define abstract methods that classes implement, allowing multiple inheritance. Interface methods are public and abstract by default. Interfaces are extended, not implemented like classes.
3) The java.lang package contains fundamental classes like Object, String, and Math. The java.util package contains utility classes like Calendar, Collections, and Random. The java.io package supports input/output with streams, files, and serialization.
Unit 2-data types,Variables,Operators,Conitionals,loops and arraysDevaKumari Vijay
The document discusses various Java data types including primitive data types like byte, short, int, long, float, double, char, boolean and their ranges. It also explains variables in Java - local variables, instance variables, static variables. Different types of operators like arithmetic, assignment, comparison, logical, bitwise operators are defined along with examples. The document also covers conditional statements like if-else, switch case and different loops in Java - for, while, do-while loops along with examples. Break and continue statements in Java loops are also explained.
1. Inheritance in Java allows classes to extend other classes and interfaces to implement other interfaces. This allows code reuse and establishes type constraints.
2. Abstract classes can contain both abstract and non-abstract methods while interfaces contain only abstract methods. Interfaces establish contracts that implementing classes must follow.
3. When constructing objects with inheritance, superclass constructors are called before subclass constructors. Abstract classes and interfaces allow incomplete implementations to be extended.
The document discusses the concept of inheritance in object-oriented programming. It defines inheritance as a child class automatically inheriting variables and methods from its parent class. The key benefits of inheritance are reusability of code and properties. The document explains how to create a subclass using the extends keyword, the constructor calling chain, and use of the super keyword. It also covers overriding and hiding methods, hiding fields, type casting, and final classes and methods.
Java does not support multiple inheritance through classes but does support multiple inheritance through interfaces. The document discusses inheritance, provides an example of single inheritance in Java, and defines multiple inheritance. It then discusses why Java does not support multiple inheritance through classes due to the "diamond problem". The document explains that Java supports multiple inheritance through interfaces by allowing interfaces to define default methods from Java 8 onwards, providing an example. It also discusses how the "diamond problem" can be resolved while using multiple inheritance through interfaces in Java.
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.
Classes and objects are fundamental concepts in object-oriented programming. A class defines common properties and behaviors of objects through fields and methods. An object is an instance of a class that represents a real-world entity with state (fields) and behavior (methods). Classes can inherit properties and behaviors from superclasses and implement interfaces. Objects are created from classes using constructors.
The document discusses Java packages and interfaces. It provides details about:
- What packages are and how they are used to prevent naming conflicts and organize classes.
- How to define a user-defined package with an example.
- What interfaces are and how they allow for multiple inheritance by implementing multiple interfaces.
- Examples of defining and implementing interfaces.
The document discusses Java packages and interfaces. It provides details about:
1) Packages in Java are used to group related classes and interfaces to prevent naming conflicts, make classes easier to find, and control access levels. Packages can contain subpackages.
2) Interfaces define abstract methods that classes implement, allowing multiple inheritance. Interface methods are public and abstract by default. Interfaces are extended, not implemented like classes.
3) The java.lang package contains fundamental classes like Object, String, and Math. The java.util package contains utility classes like Calendar, Collections, and Random. The java.io package supports input/output with streams, files, and serialization.
Unit 2-data types,Variables,Operators,Conitionals,loops and arraysDevaKumari Vijay
The document discusses various Java data types including primitive data types like byte, short, int, long, float, double, char, boolean and their ranges. It also explains variables in Java - local variables, instance variables, static variables. Different types of operators like arithmetic, assignment, comparison, logical, bitwise operators are defined along with examples. The document also covers conditional statements like if-else, switch case and different loops in Java - for, while, do-while loops along with examples. Break and continue statements in Java loops are also explained.
1. Inheritance in Java allows classes to extend other classes and interfaces to implement other interfaces. This allows code reuse and establishes type constraints.
2. Abstract classes can contain both abstract and non-abstract methods while interfaces contain only abstract methods. Interfaces establish contracts that implementing classes must follow.
3. When constructing objects with inheritance, superclass constructors are called before subclass constructors. Abstract classes and interfaces allow incomplete implementations to be extended.
The document discusses the concept of inheritance in object-oriented programming. It defines inheritance as a child class automatically inheriting variables and methods from its parent class. The key benefits of inheritance are reusability of code and properties. The document explains how to create a subclass using the extends keyword, the constructor calling chain, and use of the super keyword. It also covers overriding and hiding methods, hiding fields, type casting, and final classes and methods.
Java does not support multiple inheritance through classes but does support multiple inheritance through interfaces. The document discusses inheritance, provides an example of single inheritance in Java, and defines multiple inheritance. It then discusses why Java does not support multiple inheritance through classes due to the "diamond problem". The document explains that Java supports multiple inheritance through interfaces by allowing interfaces to define default methods from Java 8 onwards, providing an example. It also discusses how the "diamond problem" can be resolved while using multiple inheritance through interfaces in Java.
Dynamic method dispatch allows the determination of which version of an overridden method to execute at runtime based on the object's type. Abstract classes cannot be instantiated and can contain both abstract and concrete methods. Final methods and classes prevent inheritance and overriding.
A class is a blueprint that defines the data and functions of objects created from it. Constructors are special functions that are executed when an object is created from a class to initialize the object's data. Constructors can be overloaded, do not have a return type, and can only assign variables within the class.
This document discusses classes and objects in Java, including:
- Classes should implement object models and reflect real-world objects.
- Constructors prepare objects for use and finalizers perform cleanup before objects are discarded.
- Reference objects and the garbage collector determine how reachable objects are.
- Cloning objects allows copying but a deep copy duplicates contained objects.
- The Reflection API supports introspection to access class information at runtime.
- Nested and inner classes can be defined inside other classes.
Week10 packages using objects in objectskjkleindorfer
This document discusses packages in Java. Packages help organize classes by function and include common packages like java.lang for language support and java.util for utilities. To add a class to a package, the package must be created in Eclipse and the class dragged into it or created within it, which will add the package statement. Package names typically start with a reversed domain name. Static variables and methods belong to the class rather than objects. The main method is always static to allow program execution before objects exist.
This document discusses inheritance in Java. It defines inheritance as a parent-child relationship between classes that allows sharing of behavior through code reuse. The key points are: inheritance allows child classes to inherit and optionally override methods and fields from the parent class; the "extends" keyword is used to create a subclass that inherits from an existing superclass; and the "super" keyword differentiates members and calls parent constructors.
Chapter 02: Classes Objects and Methods Java by Tushar B KuteTushar B Kute
The lecture was condcuted by Tushar B Kute at YCMOU, Nashik through VLC orgnanized by MSBTE. The contents can be found in book "Core Java Programming - A Practical Approach' by Laxmi Publications.
The document discusses the Java Abstract Window Toolkit (AWT). It describes that AWT is used to create graphical user interface applications in Java and its components are platform dependent. It then lists and describes various AWT components like containers, frames, panels, labels, buttons, checkboxes, lists, text fields, text areas, canvases and scroll bars. It also discusses how to create frames using inheritance and association. Finally, it provides examples of using buttons, text fields and text areas in AWT applications.
Java classes and objects are fundamental concepts in object-oriented programming. A class defines the attributes and behaviors of a type of object, acting as a blueprint. An object is an instance of a class, having state stored in fields and behavior through methods. The document provides examples of defining a Dog class with name, breed and color attributes, along with behaviors like barking. It also demonstrates creating Puppy objects, setting fields, and calling methods. Constructors initialize new objects, and classes can contain variables, methods and constructors.
Week9 Intro to classes and objects in Javakjkleindorfer
Java programs are made of objects that interact with each other. Each object is based on a class, which describes a set of objects with the same behavior. Classes define methods that can be used with their objects. To create a class, it needs a public class name, private instance variables, constructors, getter and setter methods, and other helper methods. Constructors initialize instance variables when an object is created. Objects are instantiated from classes using the new operator.
Inheritance allows classes to inherit properties and methods from existing classes. This allows code reuse and avoids rewriting common functionality. The existing class is called the superclass, while the class inheriting is the subclass. The subclass inherits all non-private fields and methods from the superclass. Inheritance is implemented in Java using the "extends" keyword. The subclass can override methods from the superclass to modify their behavior. All classes in Java implicitly extend the Object class, which defines common methods like equals(), hashCode(), and toString().
The document summarizes a workshop on object-oriented programming (OOP) polymorphism in Java. It discusses the four principles of OOP - encapsulation, abstraction, inheritance, and polymorphism. It provides examples of implementing interfaces and abstract classes, and how classes can extend other classes and implement multiple interfaces. The key concepts are programming to interfaces rather than implementations for flexibility, and that interfaces allow implementing multiple interfaces while classes only allow single inheritance.
This document provides an overview of programming in Java. It outlines the course objectives which are to teach object-oriented programming fundamentals in Java, how to develop Java applications and applets, and create GUI-based apps that run across platforms. It then lists some reference books and introduces basic concepts like Java's history, data types, variables, and control structures. The document also compares Java to C/C++ and outlines the Java compilation and interpretation process.
The document discusses access modifiers in Java and their usage with variables, functions, and classes at different levels. It explains that access modifiers like private, protected, default, and public determine whether elements are visible from within the same class, package, subclass, or any class. Private is most restrictive while public is most accessible. It also covers other concepts like static methods, inheritance, polymorphism, abstract classes, interfaces and exception handling in Java.
Object Oriented Programming (OOP) allows developers to organize complex programs using classes and objects. OOP uses concepts like encapsulation, inheritance and polymorphism to keep data and functionality together in objects. The basic building blocks in OOP are classes, which define the properties and methods of an object, and objects, which are instances of classes. Classes can inherit properties and methods from parent classes, and objects can be identified and compared using operators like instanceof. Magic methods allow objects to override default behavior for operations like property access, method calling and object destruction.
The document discusses the use of the keywords super and this in Java. Super allows subclasses to access methods and fields of the parent class that have been overridden or hidden. It has two forms - to call the parent constructor or to access a hidden parent member. This refers to the current object and is used to avoid name conflicts between instance variables and local variables.
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.
This document discusses inheritance in Java programming. It defines inheritance as an "is-a" relationship between a superclass and subclass where the subclass is a more specific version of the superclass. The key concepts covered are method overloading, which allows methods to perform different tasks based on parameters; method overriding, which provides different implementations of methods in subclasses; and dynamic method dispatch, which determines which version of an overridden method to execute based on the object type at runtime.
Dynamic method dispatch allows the determination of which version of an overridden method to execute at runtime based on the object's type. Abstract classes cannot be instantiated and can contain both abstract and concrete methods. Final methods and classes prevent inheritance and overriding.
A class is a blueprint that defines the data and functions of objects created from it. Constructors are special functions that are executed when an object is created from a class to initialize the object's data. Constructors can be overloaded, do not have a return type, and can only assign variables within the class.
This document discusses classes and objects in Java, including:
- Classes should implement object models and reflect real-world objects.
- Constructors prepare objects for use and finalizers perform cleanup before objects are discarded.
- Reference objects and the garbage collector determine how reachable objects are.
- Cloning objects allows copying but a deep copy duplicates contained objects.
- The Reflection API supports introspection to access class information at runtime.
- Nested and inner classes can be defined inside other classes.
Week10 packages using objects in objectskjkleindorfer
This document discusses packages in Java. Packages help organize classes by function and include common packages like java.lang for language support and java.util for utilities. To add a class to a package, the package must be created in Eclipse and the class dragged into it or created within it, which will add the package statement. Package names typically start with a reversed domain name. Static variables and methods belong to the class rather than objects. The main method is always static to allow program execution before objects exist.
This document discusses inheritance in Java. It defines inheritance as a parent-child relationship between classes that allows sharing of behavior through code reuse. The key points are: inheritance allows child classes to inherit and optionally override methods and fields from the parent class; the "extends" keyword is used to create a subclass that inherits from an existing superclass; and the "super" keyword differentiates members and calls parent constructors.
Chapter 02: Classes Objects and Methods Java by Tushar B KuteTushar B Kute
The lecture was condcuted by Tushar B Kute at YCMOU, Nashik through VLC orgnanized by MSBTE. The contents can be found in book "Core Java Programming - A Practical Approach' by Laxmi Publications.
The document discusses the Java Abstract Window Toolkit (AWT). It describes that AWT is used to create graphical user interface applications in Java and its components are platform dependent. It then lists and describes various AWT components like containers, frames, panels, labels, buttons, checkboxes, lists, text fields, text areas, canvases and scroll bars. It also discusses how to create frames using inheritance and association. Finally, it provides examples of using buttons, text fields and text areas in AWT applications.
Java classes and objects are fundamental concepts in object-oriented programming. A class defines the attributes and behaviors of a type of object, acting as a blueprint. An object is an instance of a class, having state stored in fields and behavior through methods. The document provides examples of defining a Dog class with name, breed and color attributes, along with behaviors like barking. It also demonstrates creating Puppy objects, setting fields, and calling methods. Constructors initialize new objects, and classes can contain variables, methods and constructors.
Week9 Intro to classes and objects in Javakjkleindorfer
Java programs are made of objects that interact with each other. Each object is based on a class, which describes a set of objects with the same behavior. Classes define methods that can be used with their objects. To create a class, it needs a public class name, private instance variables, constructors, getter and setter methods, and other helper methods. Constructors initialize instance variables when an object is created. Objects are instantiated from classes using the new operator.
Inheritance allows classes to inherit properties and methods from existing classes. This allows code reuse and avoids rewriting common functionality. The existing class is called the superclass, while the class inheriting is the subclass. The subclass inherits all non-private fields and methods from the superclass. Inheritance is implemented in Java using the "extends" keyword. The subclass can override methods from the superclass to modify their behavior. All classes in Java implicitly extend the Object class, which defines common methods like equals(), hashCode(), and toString().
The document summarizes a workshop on object-oriented programming (OOP) polymorphism in Java. It discusses the four principles of OOP - encapsulation, abstraction, inheritance, and polymorphism. It provides examples of implementing interfaces and abstract classes, and how classes can extend other classes and implement multiple interfaces. The key concepts are programming to interfaces rather than implementations for flexibility, and that interfaces allow implementing multiple interfaces while classes only allow single inheritance.
This document provides an overview of programming in Java. It outlines the course objectives which are to teach object-oriented programming fundamentals in Java, how to develop Java applications and applets, and create GUI-based apps that run across platforms. It then lists some reference books and introduces basic concepts like Java's history, data types, variables, and control structures. The document also compares Java to C/C++ and outlines the Java compilation and interpretation process.
The document discusses access modifiers in Java and their usage with variables, functions, and classes at different levels. It explains that access modifiers like private, protected, default, and public determine whether elements are visible from within the same class, package, subclass, or any class. Private is most restrictive while public is most accessible. It also covers other concepts like static methods, inheritance, polymorphism, abstract classes, interfaces and exception handling in Java.
Object Oriented Programming (OOP) allows developers to organize complex programs using classes and objects. OOP uses concepts like encapsulation, inheritance and polymorphism to keep data and functionality together in objects. The basic building blocks in OOP are classes, which define the properties and methods of an object, and objects, which are instances of classes. Classes can inherit properties and methods from parent classes, and objects can be identified and compared using operators like instanceof. Magic methods allow objects to override default behavior for operations like property access, method calling and object destruction.
The document discusses the use of the keywords super and this in Java. Super allows subclasses to access methods and fields of the parent class that have been overridden or hidden. It has two forms - to call the parent constructor or to access a hidden parent member. This refers to the current object and is used to avoid name conflicts between instance variables and local variables.
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.
This document discusses inheritance in Java programming. It defines inheritance as an "is-a" relationship between a superclass and subclass where the subclass is a more specific version of the superclass. The key concepts covered are method overloading, which allows methods to perform different tasks based on parameters; method overriding, which provides different implementations of methods in subclasses; and dynamic method dispatch, which determines which version of an overridden method to execute based on the object type at runtime.
This document discusses inheritance in Java programming. It defines inheritance as an "is-a" relationship between a superclass and subclass where the subclass is a more specific version of the superclass. The key concepts covered include method overloading, where methods can have the same name but different signatures; method overriding, where subclasses can provide their own implementation of a method in the superclass; and dynamic method dispatch, which determines which version of an overridden method to call at runtime based on the object type.
Inheritance is a mechanism where one class acquires the properties and behaviors of another class. In Java, inheritance allows classes to reuse fields and methods from the parent class. The key types of inheritance in Java are single inheritance, multilevel inheritance, hierarchical inheritance, and method overriding which enables runtime polymorphism. The super keyword refers to the parent class, and the final keyword can restrict classes, methods, and variables from being overridden or redefined.
1. Inheritance allows a subclass to inherit properties and behaviors from a parent superclass. This allows code reusability and method overriding to achieve runtime polymorphism.
2. There are three types of inheritance in Java: single, multilevel, and hierarchical. Single inheritance involves one subclass extending one superclass, while multilevel involves deriving a subclass from another derived class. Hierarchical inheritance involves one superclass being inherited by multiple subclasses.
3. The super keyword is used to access members of the parent superclass like methods and variables, or to call the parent superclass constructor. Method overriding occurs when a subclass defines a method with the same name and parameters as a method in its parent superclass.
The document discusses inheritance in Java. It defines inheritance as a mechanism where a new class is derived from an existing class, allowing the subclass to inherit properties and methods from the superclass. The key advantages of inheritance include code reuse, flexibility, and abstraction. The document also covers different types of inheritance like single, multilevel, hierarchical and multiple inheritance. It explains concepts like overriding, super keyword, abstract classes and final keyword in the context of inheritance.
This 5-day Java workshop covers object-oriented programming (OOP) inheritance. The key concepts discussed include the four pillars of OOP - encapsulation, abstraction, inheritance, and polymorphism. Inheritance allows classes to extend existing classes to share common attributes and methods, while also adding new unique functionality. The workshop provides examples of defining parent and child classes, using inheritance, overriding methods, and casting between classes. Resources for further learning about Java and OOP are also listed.
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.
- 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 inheritance in Java programming. It defines inheritance as a mechanism where a subclass acquires the properties and behaviors of a superclass. It describes the key types of inheritance in Java including single, multilevel, and hierarchical inheritance. It also outlines some advantages, such as code reusability and reliability, and disadvantages, such as increased coupling between classes.
Know the difference between Inheritance and aggregation
Understand how inheritance is done in Java
Learn polymorphism through Method Overriding
Learn the keywords : super and final
Understand the basics of abstract class
The document discusses inheritance in object-oriented programming. It defines inheritance as a mechanism where a subclass inherits properties and behaviors from its parent superclass. The key points are:
- A subclass inherits attributes and methods from its superclass. The subclass can also define its own attributes and methods or override existing superclass methods.
- There are two types of inheritance - single inheritance where a subclass inherits from one superclass, and multiple inheritance which is not supported in Java.
- Access modifiers like public, private, protected determine which members of the superclass are accessible to subclasses. Private members cannot be accessed by subclasses.
- The extends keyword is used to create a subclass that inherits from an existing superclass. The subclass inherits all non
This chapter discusses decision making, object-oriented fundamentals, inner classes, and exception handling in Java. It describes the use of if and switch statements for decision making. It also covers access specifiers, encapsulation, inheritance, polymorphism, abstract classes, interfaces, inner classes, and exceptions.
This document provides an overview of inheritance in object-oriented programming. It defines inheritance as a child class automatically inheriting variables and methods from its parent class. Benefits include reusability, where behaviors are defined once in the parent class and shared by all subclasses. The document discusses how to derive a subclass using the extends keyword, what subclasses can do with inherited and new fields and methods, and how constructors are called following the constructor calling chain. It also covers overriding and hiding methods and fields, type casting between subclasses and superclasses, and final classes and methods that cannot be extended or overridden.
Inheritance in java is a mechanism in which one object acquires all the properties and behaviors of parent object. The idea behind inheritance in java is that you can create new classes that are built upon existing classes.
This document provides an overview of object-oriented programming (OOP) concepts, including classes, visibility, encapsulation, inheritance, polymorphism, and abstraction. A class defines the structure and behavior of an object, and can contain both data and functions. Visibility determines which members can be accessed from inside or outside a class. Encapsulation wraps data and functions together, while inheritance allows classes to inherit attributes from parent classes. Polymorphism enables different implementations of methods with the same name. Abstraction hides implementation details and provides a public interface.
This document provides an overview of object-oriented programming (OOP) concepts including classes, visibility, encapsulation, inheritance, polymorphism, and abstraction. A class defines the structure and behavior of an object and includes both data and functions. Visibility determines which members can be accessed from within or outside the class. Encapsulation wraps data and functions into a single unit. Inheritance allows a subclass to inherit properties and behaviors from a parent class. Polymorphism enables classes to provide different implementations of methods with the same name. Abstraction hides implementation details and provides essential public methods to manipulate object data without knowing internal details.
The document discusses inheritance in object-oriented programming. It defines inheritance as a class acquiring the properties and methods of another class. Inheritance provides code reusability so that a class only needs to define unique features and can inherit common features from a parent class. Child classes extend and inherit from parent classes. The extends keyword is used to inherit from a parent class.
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.
The document discusses computer architecture and describes the basic components of a computer. It discusses the instruction cycle which involves fetching instructions from memory, decoding them, reading the effective address from memory, and executing the instruction. The basic computer has three types of instructions - memory reference, register reference, and input/output. Memory reference instructions refer to memory addresses and use direct or indirect addressing. Register reference instructions perform operations on registers. Input/output instructions are used for communication with external devices. The instruction cycle is then completed by fetching and executing the next instruction.
The document provides an overview of operating systems, including what they are, their goals and components. It describes how operating systems act as an intermediary between the user and computer hardware, executing programs and making resource allocation more efficient. It also summarizes the different types of operating systems like batch processing systems, time-sharing systems, personal computer systems, distributed systems, and real-time systems.
The document discusses various components of an Android application. It describes the four main types of app components: Activities, Services, Broadcast Receivers, and Content Providers. It provides details about what each component type represents and how it is implemented. It also discusses some additional concepts like fragments, views, layouts, intents and resources that are involved in building Android apps.
Mobile computing allows transmission of data, voice, and video through wireless devices without a fixed connection. It involves mobile communication infrastructure, mobile hardware devices like smartphones and tablets, and mobile software operating systems. The technology has advanced from 1G analog cellular to 2G digital cellular, 3G broadband cellular, 4G high-speed data, and upcoming 5G which will provide wireless internet speeds over 1 Gbps. Mobile computing provides benefits like location flexibility and enhanced productivity but also poses problems regarding security, authentication, health issues, and addiction.
A Monte Carlo simulation involves modeling a system with random variables to estimate outcomes. It repeats calculations using randomly generated values for the variables and averages the results. The document discusses using Monte Carlo simulations to model demand in business situations with uncertain variables. Examples show generating random numbers to simulate daily product demand over multiple days and calculating the average demand from the results.
The document discusses decision making under conditions of risk and uncertainty. It defines key terms like decision maker, alternatives, events, and payoff tables. It explains three types of decision making: decisions under certainty where outcomes are known; decisions under risk where outcomes are unknown but probabilities are known; and decisions under uncertainty where neither outcomes nor probabilities are known. It then discusses various decision making criteria that can be used under different conditions like maximax, maximin, minimax, Laplace, and Hurwicz criteria. Expected monetary value is introduced as a method to evaluate decisions under risk. Decision trees are also defined as a way to visually represent decision problems involving uncertainty.
This document provides information about project management applications including definitions of a project, project life cycle, and examples of projects. It also discusses network planning techniques such as Program Evaluation and Review Technique (PERT) and Critical Path Method (CPM). The key steps in CPM including forward and backward passes to determine earliest and latest start/finish times are explained. Formulas for calculating total float, free float, and independent float are provided. An example problem demonstrates drawing a network diagram and identifying the critical path and project duration.
The document describes a Monte Carlo simulation process for modeling uncertainty. It provides examples of simulating daily demand for a bakery and a car rental company using random numbers and probability distributions. For the bakery, the average daily demand over 5 days was calculated to be 17 units. For the car rental company, the average number of trips per week over 10 weeks was calculated to be 2.8 trips. The document demonstrates how Monte Carlo simulation can be used to model systems with uncertain variables and calculate average outcomes.
This document provides an overview of system dynamics and systems thinking. It defines key terms like systems, static vs dynamic systems, feedback loops, stocks and flows. Systems thinking focuses on how parts of a system interrelate and how systems work over time. System dynamics uses feedback loops and stocks/flows to model how complex systems change over time. It involves conceptualizing the system, formulating stock/flow diagrams, testing the model, and implementing it to test policies. Causal loop diagrams and stock/flow diagrams are introduced as tools to understand system structure and behavior.
This document discusses discrete event simulation and queueing systems. It provides definitions and explanations of key concepts in discrete event simulation including: entities and attributes, events, activities, system state, and components of discrete event simulation models. It also defines concepts related to queueing systems such as arrival processes, service times, queue disciplines, and how to simulate single and multiple server queueing systems. Simulation is presented as an important tool for analyzing complex, stochastic queueing systems when mathematical analysis is not possible.
Simulation involves developing a model of a real-world system over time to analyze its behavior and performance. The key aspects covered in this document include defining simulation as modeling the operation of a system over time through artificial history generation and observation. Simulation models can be used as analysis and design tools to predict the effects of changes to a system before actual implementation. Discrete event simulation is discussed as a common technique that models systems with state changes occurring at discrete points in time. The document also outlines the steps in a typical simulation study including problem formulation, model conceptualization, experimentation and analysis.
The document discusses Monte Carlo simulation methods. It begins by defining key terms like systems, models, simulation, random numbers, and Monte Carlo simulation. It then provides more details on Monte Carlo simulations, explaining that they are used to predict outcomes when random variables are present by running the model repeatedly with different random variable values and averaging the results. Several examples are given of fields that use Monte Carlo simulations. The document concludes by outlining the typical steps involved in a Monte Carlo simulation.
Java is an object-oriented programming language that was initially developed by James Gosling at Sun Microsystems in 1991. It is free to use, runs on all platforms, and is widely used for both desktop and mobile applications as well as large systems. Java code is compiled to bytecode that runs on a Java Virtual Machine, making Java programs platform independent. Key features of Java include being object-oriented, robust, secure, portable, high performance, and having a simple syntax. Java is commonly used to develop web applications, mobile apps, games, and for big data processing.
Introduction to design and analysis of algorithmDevaKumari Vijay
This document defines algorithms and describes how to analyze their efficiency. It states that an algorithm is a set of unambiguous instructions that accepts input and produces output within a finite number of steps. The document outlines criteria algorithms must satisfy like being definite, finite, and effective. It also describes different representations of algorithms like pseudocode and flowcharts. The document then discusses analyzing algorithms' time and space efficiency using asymptotic notations like Big-O, Big-Omega, and Big-Theta. It defines these notations and provides examples to classify algorithms' order of growth.
Operations research is a scientific approach to decision making that seeks to optimize systems with scarce resources. It uses mathematical modeling to formulate and solve problems. The methodology involves formulating the problem, developing a mathematical model, deriving a solution from the model, selecting alternatives, validating the model, implementing and evaluating recommendations. Linear programming is an optimization technique that finds optimal values for decision variables in an objective function subject to constraints. It involves writing decision variables, formulating the objective function and constraints, and adding non-negativity constraints.
हिंदी वर्णमाला पीपीटी, hindi alphabet PPT presentation, hindi varnamala PPT, Hindi Varnamala pdf, हिंदी स्वर, हिंदी व्यंजन, sikhiye hindi varnmala, dr. mulla adam ali, hindi language and literature, hindi alphabet with drawing, hindi alphabet pdf, hindi varnamala for childrens, hindi language, hindi varnamala practice for kids, https://www.drmullaadamali.com
A Strategic Approach: GenAI in EducationPeter Windle
Artificial Intelligence (AI) technologies such as Generative AI, Image Generators and Large Language Models have had a dramatic impact on teaching, learning and assessment over the past 18 months. The most immediate threat AI posed was to Academic Integrity with Higher Education Institutes (HEIs) focusing their efforts on combating the use of GenAI in assessment. Guidelines were developed for staff and students, policies put in place too. Innovative educators have forged paths in the use of Generative AI for teaching, learning and assessments leading to pockets of transformation springing up across HEIs, often with little or no top-down guidance, support or direction.
This Gasta posits a strategic approach to integrating AI into HEIs to prepare staff, students and the curriculum for an evolving world and workplace. We will highlight the advantages of working with these technologies beyond the realm of teaching, learning and assessment by considering prompt engineering skills, industry impact, curriculum changes, and the need for staff upskilling. In contrast, not engaging strategically with Generative AI poses risks, including falling behind peers, missed opportunities and failing to ensure our graduates remain employable. The rapid evolution of AI technologies necessitates a proactive and strategic approach if we are to remain relevant.
Macroeconomics- Movie Location
This will be used as part of your Personal Professional Portfolio once graded.
Objective:
Prepare a presentation or a paper using research, basic comparative analysis, data organization and application of economic information. You will make an informed assessment of an economic climate outside of the United States to accomplish an entertainment industry objective.
This slide is special for master students (MIBS & MIFB) in UUM. Also useful for readers who are interested in the topic of contemporary Islamic banking.
Physiology and chemistry of skin and pigmentation, hairs, scalp, lips and nail, Cleansing cream, Lotions, Face powders, Face packs, Lipsticks, Bath products, soaps and baby product,
Preparation and standardization of the following : Tonic, Bleaches, Dentifrices and Mouth washes & Tooth Pastes, Cosmetics for Nails.
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...Dr. Vinod Kumar Kanvaria
Exploiting Artificial Intelligence for Empowering Researchers and Faculty,
International FDP on Fundamentals of Research in Social Sciences
at Integral University, Lucknow, 06.06.2024
By Dr. Vinod Kumar Kanvaria
it describes the bony anatomy including the femoral head , acetabulum, labrum . also discusses the capsule , ligaments . muscle that act on the hip joint and the range of motion are outlined. factors affecting hip joint stability and weight transmission through the joint are summarized.
This presentation was provided by Steph Pollock of The American Psychological Association’s Journals Program, and Damita Snow, of The American Society of Civil Engineers (ASCE), for the initial session of NISO's 2024 Training Series "DEIA in the Scholarly Landscape." Session One: 'Setting Expectations: a DEIA Primer,' was held June 6, 2024.
A review of the growth of the Israel Genealogy Research Association Database Collection for the last 12 months. Our collection is now passed the 3 million mark and still growing. See which archives have contributed the most. See the different types of records we have, and which years have had records added. You can also see what we have for the future.
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...PECB
Denis is a dynamic and results-driven Chief Information Officer (CIO) with a distinguished career spanning information systems analysis and technical project management. With a proven track record of spearheading the design and delivery of cutting-edge Information Management solutions, he has consistently elevated business operations, streamlined reporting functions, and maximized process efficiency.
Certified as an ISO/IEC 27001: Information Security Management Systems (ISMS) Lead Implementer, Data Protection Officer, and Cyber Risks Analyst, Denis brings a heightened focus on data security, privacy, and cyber resilience to every endeavor.
His expertise extends across a diverse spectrum of reporting, database, and web development applications, underpinned by an exceptional grasp of data storage and virtualization technologies. His proficiency in application testing, database administration, and data cleansing ensures seamless execution of complex projects.
What sets Denis apart is his comprehensive understanding of Business and Systems Analysis technologies, honed through involvement in all phases of the Software Development Lifecycle (SDLC). From meticulous requirements gathering to precise analysis, innovative design, rigorous development, thorough testing, and successful implementation, he has consistently delivered exceptional results.
Throughout his career, he has taken on multifaceted roles, from leading technical project management teams to owning solutions that drive operational excellence. His conscientious and proactive approach is unwavering, whether he is working independently or collaboratively within a team. His ability to connect with colleagues on a personal level underscores his commitment to fostering a harmonious and productive workplace environment.
Date: May 29, 2024
Tags: Information Security, ISO/IEC 27001, ISO/IEC 42001, Artificial Intelligence, GDPR
-------------------------------------------------------------------------------
Find out more about ISO training and certification services
Training: ISO/IEC 27001 Information Security Management System - EN | PECB
ISO/IEC 42001 Artificial Intelligence Management System - EN | PECB
General Data Protection Regulation (GDPR) - Training Courses - EN | PECB
Webinars: https://pecb.com/webinars
Article: https://pecb.com/article
-------------------------------------------------------------------------------
For more information about PECB:
Website: https://pecb.com/
LinkedIn: https://www.linkedin.com/company/pecb/
Facebook: https://www.facebook.com/PECBInternational/
Slideshare: http://www.slideshare.net/PECBCERTIFICATION
2. • Inheritance is the mechanism in java by which one class acquires the features(fields and
methods) of another class.
Important terminology:
• Super Class: The class whose features are inherited is known as super class(or a base class
or a parent class).
• Sub Class: The class that inherits the other class is known as sub class(or a derived class,
extended class, or child class). The subclass can add its own fields and methods in addition to
the superclass fields and methods.
• Reusability: Inheritance supports the concept of “reusability”, i.e. when we want to create a
new class and there is already a class that includes some of the code that we want, we can
derive our new class from the existing class. By doing this, we are reusing the fields and
methods of the existing class.
• The keyword used for inheritance is extends.
Syntax :
class derived-class extends base-class
{
//methods and fields
}
3. class Employee{
float salary=4000;
}
class Programmer extends Employee{
int bonus=1000;
public static void main(String args[]){
Programmer p=new Programmer();
System.out.println("Programmer salary is:"+p.salary); //parent class variable
System.out.println("Bonus of Programmer is:"+p.bonus); /child class variable
}
}
4. class Calculation
{
int z;
public void addition(int x, int y)
{ z = x + y;
System.out.println("The sum of the given numbers:"+z);
}
public void Subtraction(int x, int y)
{ z = x - y;
System.out.println("The difference between the given numbers:"+z);
} }
public class My_Calculation extends Calculation
{
public void multiplication(int x, int y)
{ z = x * y;
System.out.println("The product of the given numbers:"+z); }
public static void main(String args[])
{
int a = 20, b = 10;
My_Calculation demo = new My_Calculation();
demo.addition(a, b);
demo.Subtraction(a, b);
demo.multiplication(a, b); } }
5. • Child class objects has variables/methods of parent class as well as itself.
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.
Multiple inheritance is not supported using classes in java.
7.
8. SINGLE INHERITANCE
• In single inheritance, subclasses inherit the features of one superclass. In image below,
the class A serves as a base class for the derived class B.
9. class Animal{
void eats(){System.out.println(“All animals eat...");}
}
class Dog extends Animal{
void barks(){System.out.println(“only dogs barks...");}
}
class TestInheritance{
public static void main(String args[]){
Dog d=new Dog();
d.barks();
d.eats();
}
}
10. class one
{
public void print_one()
{
System.out.println(“Kristu");
}
}
class two extends one
{
public void print_ftwo()
{
System.out.println(“Jayanti");
}
}
public class Main
{
public static void main(String[] args)
{
two g = new two();
g.print_one();
g.print_two();
}
}
11. MULTILEVEL INHERITANCE
• In Multilevel Inheritance, a derived class will be inheriting a base class and as well as the
derived class also act as the base class to other class.
• In below image, the class A serves as a base class for the derived class B, which in turn
serves as a base class for the derived class C.
12. class Animal{
void eat()
{System.out.println(“All animals eat...");}
}
class Dog extends Animal{
Void bark()
{System.out.println(“Only dogs barkis");}
}
class BabyDog extends Dog{
void weep()
{System.out.println(“Baby dogs weep");}
}
class TestInheritance2{
public static void main(String args[]){
BabyDog d=new BabyDog();
d.weep();
d.bark();
d.eat();
}
}
13. class one
{
public void print_one()
{ System.out.println(“Kristu"); }
}
class two extends one
{
public void print_two()
{ System.out.println(“Jayanti"); }
}
class three extends two
{
public void print_three()
{ System.out.println(“College"); }
}
public class Main
{
public static void main(String[] args)
{
three g = new three();
g.print_one();
g.print_two();
g.print_three();
}
}
14. HIERARCHICAL INHERITANCE
• In Hierarchical Inheritance, one class serves as a superclass (base class) for more than
one sub class.
• In below image, the class A serves as a base class for the derived class B,C and D.
15. class one
{
public void print_one)
{
System.out.println(“Kristu");
}
}
class two extends one
{
public void print_two()
{
System.out.println(“Jayanti");
}
}
class three extends one
{
/*............*/
}
public class Main
{
public static void main(String[] args)
{
three g = new three();
g.print_one();
two t = new two();
t.print_two();
g.print_one();
}
}
16. class A {
public void methodA() {
System.out.println("method of Class A");
}
}
class B extends A {
public void methodB() {
System.out.println("method of Class B");
}
}
class C extends A {
public void methodC() {
System.out.println("method of Class C");
}
}
class D extends A {
public void methodD() {
System.out.println("method of Class D");
}
}
class JavaExample
{
public static void main(String args[])
{
B obj1 = new B();
C obj2 = new C();
D obj3 = new D();
//All classes can access the method of
class A
obj1.methodA();
obj2.methodA();
obj3.methodA();
}
}
17. METHOD OVERRIDING
• Declaring a method in sub class which is already present in parent class is known as
method overriding, provided that it is not marked final..
• Overriding is done so that a child class can give its own implementation to a method
which is already provided by the parent class.
• In this case the method in parent class is called overridden method and the method in
child class is called overriding method.
• The version of a method that is executed will be determined by the object that is used to
invoke it. If an object of a parent class is used to invoke the method, then the version in
the parent class will be executed, but if an object of the subclass is used to invoke the
method, then the version in the child class will be executed.
• In other words, it is the type of the object being referred to (not the type of the reference
variable) that determines which version of an overridden method will be executed.
18. class Animal {
public void move() {
System.out.println("Animals can move");
}
}
class Dog extends Animal {
public void move() {
System.out.println("Dogs can walk and run");
}
}
public class TestDog {
public static void main(String args[]) {
Animal a = new Animal(); // Animal robject
Animal b = new Dog(); // Animal reference but Dog object
a.move(); // runs the method in Animal class
b.move(); // runs the method in Dog class
}
}
19. • A method declared final cannot be overridden.
• A method declared static cannot be overridden but can be re-declared.
• If a method cannot be inherited, then it cannot be overridden.
• Constructors cannot be overridden.
• The access level cannot be more restrictive than the overridden method's access level.
For example: If the superclass method is declared public then the overridding method in
the sub class cannot be either private or protected.
• The argument list should be exactly the same as that of the overridden method.
• The return type should be the same or a subtype of the return type declared in the original
overridden method in the superclass.
20. class Parent {
// private methods are not overridden
private void m1()
{
System.out.println("From parent m1()"); }
protected void m2()
{
System.out.println("From parent m2()"); }
}
class Child extends Parent {
// new m1() method ,unique to Child class
private void m1()
{
System.out.println("From child m1()");
}
// overriding method with more accessibility
public void m2()
{
System.out.println("From child m2()");
}
}
// Driver class
class Main {
public static void main(String[] args)
{
Parent obj1 = new Parent();
obj1.m2();
Child obj2 = new Child();
Parent obj3=new Child();//Upcasting
obj2.m2(); //overriding
obj3.m2();
}
}
21. • When Parent class reference variable refers to Child class object, it is known
as Upcasting.
• In Java this is helpful in scenarios where multiple child classes extends one parent class.
In those cases we can create a parent class reference and assign child class objects to it.
22. DYNAMIC METHOD DISPATCH OR RUNTIME POLYMORPHISM
• Method overriding is one of the ways in which Java supports Runtime Polymorphism.
Dynamic method dispatch is the mechanism by which a call to an overridden method is
resolved at run time, rather than compile time.
• When an overridden method is called through a superclass reference, Java determines
which version(superclass/subclasses) of that method is to be executed based upon the
type of the object being referred to at the time the call occurs. Thus, this determination is
made at run time.
• At run-time, it depends on the type of the object being referred to (not the type of the
reference variable) that determines which version of an overridden method will be
executed
• A superclass reference variable can refer to a subclass object. This is also known as
upcasting. Java uses this fact to resolve calls to overridden methods at run time.
•
23. class Game
{
public void type()
{
System.out.println("Indoor & outdoor");
}
}
Class Cricket extends Game
{
public void type()
{
System.out.println("outdoor game");
}
}
Class dynamicdispatch{
public static void main(String[] args)
{
Game gm = new Game();
Cricket ck = new Cricket();
gm.type();
ck.type();
gm = ck;//gm refers to Cricket object,dynamic
method dispatch
gm.type(); //calls Cricket's version of type
}
}
24. class Shape{
void draw(){System.out.println("drawing..");}
}
class Rectangle extends Shape{
void draw(){System.out.println("drawing rectangle..");
}
}
class Circle extends Shape{
void draw(){System.out.println("drawing circle...");}
}
class Triangle extends Shape{
void draw(){System.out.println("drawing triangle...");}
}
class TestPolymorphism2{
public static void main(String args[])
{
Shape s;
s=new Rectangle();
s.draw();
s=new Circle();
s.draw();
s=new Triangle();
s.draw();
}
}
25. OVERLOADING
• Method Overloading is a feature that allows a class to have more than one method having
the same name, if their argument lists are different.
• 1. Number of parameters.
For example: This is a valid case of overloading
add(int, int) add(int, int, int)
• 2. Data type of parameters.
For example:add(int, int) add(int, float)
• 3. Sequence of Data type of parameters.
For example:add(int, float) add(float, int)
• Invalid case of method overloading:if two methods have same name, same parameters
and have different return type, then this is not a valid method overloading example. This
will throw compilation error.
int add(int, int) float add(int, int)
26. • Method overloading is an example of Static Polymorphism.
• Points to Note:
1. Static Polymorphism is also known as compile time binding or early binding.
2. Static binding happens at compile time. Method overloading is an example of static
binding where binding of method call to its definition happens at Compile time.
27. class DisplayOverloading
{
public void disp(char c)
{
System.out.println(c);
}
public void disp(char c, int num) //different number of parameters
{
System.out.println(c + " "+num);
}
}
class Sample
{
public static void main(String args[])
{
DisplayOverloading obj = new DisplayOverloading();
obj.disp('a');
obj.disp('a',10);
}
}
28. class DisplayOverloading2
{
public void disp(char c)
{
System.out.println(c);
}
public void disp(int c)different type of paarameter
{
System.out.println(c );
}
}
class Sample2
{
public static void main(String args[])
{
DisplayOverloading2 obj = new DisplayOverloading2();
obj.disp('a');
obj.disp(5);
}
}
29. class DisplayOverloading3
{
public void disp(char c, int num)
{
System.out.println("I’m the first definition of method disp");
}
public void disp(int num, char c)//different sequence of parameters
{
System.out.println("I’m the second definition of method disp" );
}
}
class Sample3
{
public static void main(String args[])
{
DisplayOverloading3 obj = new DisplayOverloading3();
obj.disp('x', 51 );
obj.disp(52, 'y');
}
}
30. ABSTRACT CLASS AND ABSTRACT METHOD
• 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.
• 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.
• A method which is declared as abstract and does not have implementation is known as an
abstract method.
• If a class includes abstract methods, then the class itself must be declared abstract
31. abstract class Shape{
abstract void draw();
public void nonabstract(){
System.out.println(“Non abstrat method");}
}
class Rectangle extends Shape{
void draw(){System.out.println("drawing rectangle");}
}
class Circle1 extends Shape{
void draw(){System.out.println("drawing circle");}
}
class AbstractionTest1{
public static void main(String args[]){
Shape s=new Circle1();
s.draw();
s.nonabstractmethod();
}
}
32. SUPER KEYWORD
• The super keyword in Java is a reference variable which is used to refer immediate
parent class object.
• 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.
33. Use of super with variables
class Vehicle
{
int maxSpeed = 120;
}
/* sub class Car extending vehicle */
class Car extends Vehicle
{
int maxSpeed = 180;
void display()
{
/* print maxSpeed of base class
(vehicle) */
System.out.println("Maximum Speed: " +
super.maxSpeed);
}
}
/* Driver program to test */
class Test
{
public static void main(String[] args)
{
Car small = new Car();
small.display();
}
}
34. • Use of super with methods
class Person
{
void message()
{
System.out.println("This is person class");
}
}
class Student extends Person
{
void message()
{
System.out.println("This is student class");
}
void display()
{ // will invoke or call current class message()
method
message();
// will invoke or call parent class message()
method
super.message();
}
}
class Test
{
public static void main(String args[])
{
Student s = new Student();
// calling display() of Student
s.display();
}
}
35. Use of super with constructors
class Person
{
Person()
{
System.out.println("Person class
Constructor");
}
}
class Student extends Person
{
Student()
{
// invoke or call parent class constructor
super();
System.out.println("Student class
Constructor");
}
}
class Test
{
public static void main(String[] args)
{
Student s = new Student();
}
}
36. • Call to super() must be first statement in Derived(Student) Class
constructor.
• If a constructor does not explicitly invoke a superclass constructor, the
Java compiler automatically inserts a call to the no-argument
constructor of the superclass.
• If the superclass does not have a no-argument constructor, you will
get a compile-time error.
• If a subclass constructor invokes a constructor of its superclass, either
explicitly or implicitly, a whole chain of constructors called, all the way
back to the constructor of Object. This, in fact, is the case. It is
called constructor chaining..
37. THIS KEYWORD
• ‘this’ is a reference variable that refers to the current object.
• The most common use of the this keyword is to eliminate the confusion between class
attributes and parameters with the same name
• Invoke current class constructor
• Invoke current class method
38. class Test
{
int a;
int b;
// Parameterized constructor
Test(int a, int b)
{
this.a = a;
this.b = b;
}
void display()
{
//Displaying value of variables a and b
System.out.println("a = " + a + " b = " + b);
}
}
class ThisEx1{
public static void main(String[] args)
{
Test object = new Test(10, 20);
object.display();
}
}
39. class Test
{
int a;
int b;
//Default constructor
Test()
{
this(10, 20);
System.out.println("Inside default constructor n");
}
//Parameterized constructor
Test(int a, int b)
{
this.a = a;
this.b = b;
System.out.println("Inside parameterized
constructor");
}
}
Class thisEx2{
public static void main(String[] args)
{
Test object = new Test();
}
}