Blog Introductions
In this blog contains tutorials about HTML Tutorials, Python Tutorials, CSS Tutorials, How to, PHP Tutorials, Java Tutorials, C++ Tutorials, Tutorials, Examples, Source code,Learning,
Tips and Software development services. Java OOP and Object orriented programing | Java tutorials Bestitworriors.
Java OOP and Object orriented programing
Java OOP and Object orriented programing - OOP stands for object orriented programing.In object oriented programing we talk aboout object and its classes.Object define as any thing which have some properties and methods.For exemple a car is an object that have properties like color , height ,width,waight etc and methods like start , stop ,drive etc.Object oriented programing is fast and easier to execute.OOP provide clear structure of code .
Some Key Points of Java OOP
- OOP stands for object orriented programing
- Object define as any thing which have some properties and functions
- For working on object we use class
- Class have some properties like datamembers or variables
- Class have some function like methods or class function
- Class data member or function start by access specifier
- Access specifier is know private , public or protected
- Class have constructors
- Java OOP support polymorphism , Encapsulation and Inheritance etc
- Class have static method also and can be work or run without creating an object just call it.
- Static method can be called without creating an object
- Public method must be called after creating an object
Code
public
class myclass {
// Static method
int x;
public myclass() {
x = 5;
}
static void myStaticMethod() {
System.out.println("Static methods can be called ");
}
// Public method
public void myPublicMethod() {
System.out.println("Public methods must be called");
}
// Main method
public static void main(String[] args) {
myStaticMethod(); // Call the static method
// myPublicMethod(); This would compile an error
myclass myObj = new myclass(); // Create an object of Main
myObj.myPublicMethod(); // Call the public method on the object
System.out.println(myObj.x);
}
}
OutPut
Static methods can be called
Public methods must be called
5
Public methods must be called
5
0 Comments