Augumented course for vtu topic non static method in java

ESAIKRISHNA 5 views 9 slides May 06, 2024
Slide 1
Slide 1 of 9
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9

About This Presentation

ppt for


Slide Content

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING Jyothy Institute of Technology COURSE CODE : 18CSAUG1 Course name : Student Presentation and Feedback Name : E Sai Krishna USN:1JT20CS029 Date : 11 /03/2024 Non Static Method In Java

AGENDA INTRODUCTION EXPLANATION APPLICATIONS ADVANTAGES AND DISADVANTAGES CONCLUSION REFERENCES DEPT OF CSE, 2023-2024

INTRODUCTION Non-static methods are a fundamental concept in Java programming, playing a crucial role in object-oriented programming. They enable classes to define behaviors that are specific to individual instances, contributing to the flexibility and modularity of Java applications.

EXPLANATION Definition: Non-static methods in Java are functions associated with instances of a class, allowing objects to perform actions and manipulate their internal state. Association with Instances: Unlike static methods, which belong to the class itself, non-static methods operate on specific instances, accessing instance variables and enabling object-oriented behaviors. Difference from Static Methods: Non-static methods are invoked using object references and can access instance-specific data, whereas static methods are called directly on the class and cannot access instance variables without an object reference.

APPLICATION Object-Oriented Programming: Non-static methods are foundational in object-oriented programming, facilitating the encapsulation of behavior within objects and promoting code reusability. Real-World Examples: In software development, non-static methods are employed extensively in designing classes, modeling real-world entities, and implementing business logic. Examples include methods to manipulate customer data in an e-commerce application or to perform calculations in scientific simulations.

EXAMPLE import java.util.Random; public class MyClass { int number; public static void main(String[] args) { MyClass t1 = new MyClass(); t1.number = new Random().nextInt(); MyClass t2 = new MyClass(); t2.number = new Random().nextInt(); MyClass t3 = new MyClass(); t3.number = new Random().nextInt(); System.out.println(t1.number); System.out.println(t2.number); System.out.println(t3.number); } } java -cp /tmp/bcabnxXzUi MyClass -952368917 1521604728 -2128061400

import java.util.Random; public class MyClass { static int number; public static void main(String[] args) { MyClass t1 = new MyClass(); t1.number = new Random().nextInt(); MyClass t2 = new MyClass(); t2.number = new Random().nextInt(); MyClass t3 = new MyClass(); t3.number = new Random().nextInt(); System.out.println(MyClass.number); System.out.println(t2.number); System.out.println(t3.number); } } java -cp /tmp/PDmhw6vQ63 MyClass 1974315283 1974315283 1974315283

public class Test1 { public static void show(){ System.out.println("static method"); } public void show1(){ System.out.println("non-static method"); } } public class Test2{ public static void main(String[] args){ Test1.show(); Test1.show1();// error Test1 t1 = new Test1(); t1.show1(); } }

REFERENCES Books: "Java: A Beginner's Guide" by Herbert Schildt "Effective Java" by Joshua Bloch Online Resources: Oracle's Java Documentation : Tutorialspoint Java Tutorial THANK YOU
Tags