Skip to Main Content

Java Basic

N_RajJul 1 2015 — edited Jul 1 2015

Hi,

I am new bee to Java and also Programming language.Started to learn from http://www.javatpoint.com/object-and-class-in-java.

I have few doubts about the example.

class Student2{
int rollno;
String name;

void insertRecord(int r, String n){  //method
  rollno=r;
  name=n;
}

void displayInformation(){System.out.println(rollno+" "+name);}//method

public static void main(String args[]){
  Student2 s1=new Student2();
  Student2 s2=new Student2();

  s1.insertRecord(111,"Karan");
  s2.insertRecord(222,"Aryan");

  s1.displayInformation();
  s2.displayInformation();

}
}

1,I beleive,Instance variable are rollno,name.Can we use this instance variable anywhere in the program.

2,Why Instance variable is assigned in the method ( insertRecord ).when it used?

3, public static void main(String args[]){ - Is method or not?

4,Student2 s1=new Student2(); I  understand new is keyword to create a object,Student2( ) is object name.I couldn't understand Student2 s1.

5,What is the relation between  method and objects.Objects always create within the menthod

6,I heard many times from the developers/trianer about Void doesn't return any value.

7,Does the every java program have main()?

Kindly anyone help me.

Thanks

Comments
Post Details
Added on Jul 1 2015
6 comments
1,001 views