java class and objects program
program:-1
Syntex of class
public class class_name{
//field;
//method;
}
2.java program to how to define a class and fields.
class Demo
{
int id;
String name;
public static void main(String args[]){
Demo s1= new Demo();
System.out.println(s1.id);
System.out.println(s1.name);
}
}
//output
//0
//null
3.java program to demonstrate having the main method in another class.
class Demo
{
int id;
String name;
}
class sec{
public static void main(String args[]){
Demo s1= new Demo();
System.out.println(s1.id);
System.out.println(s1.name);
}
}
//output
//0
//null
Comments
Post a Comment