Class is a blueprint or template which
you can create as many objects as you
like.Object is a member or instance
of a class.Class is declared using class keyword,
Object is created through
new keyword mainly. A class is a template
for objects. A classdefinesobject properties including a valid range
of values, and a default value.
A class also describes object behavior.
publicclassHelloWorld {
publicstaticvoidmain(String[] args) {
classNumber{
int number;
publicbooleanisPos(){
if(number >0){
returntrue;
} else {
returnfalse;
}
}
}
Number myNumber =newNumber();
myNumber.number =7;
if(myNumber.isPos()){
System.out.println(myNumber.number +" is positive!!!");
} else {
System.out.println(myNumber.number +" is not positive!!!");
}
}
}
Posted by: Guest
on March-10-2020
1
using class in java
publicclassHelloWorld {
publicstaticvoidmain(String[] args) {
// how to use class in javaclassUser{
int score;
// method that can be used outside the classpublicbooleanhasWon(){
if(score >=100){
returntrue;
} else {
returnfalse;
}
}
}
User dave =newUser();
dave.score =20;
System.out.println(dave.hasWon());
}
}
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems
resetting your password contact us
Check Your Email and Click on the link sent to your email