Initializing the Person class instance variable in Mainclass (Directly Storing Data) - LearnHowToCode SarkariResult.com Interview Questions and Answers LearnHowToCodeOnline
Initializing the Person class instance variable in demo class (Directly Storing Data)

Initializing the Person class instance variable in Mainclass (Directly Storing Data)

class Person{
// inatamce variable initialize here
String name="VenKat";
  int age=30;
//methods
void talk(){
System.out.println("hello I am "+name);
System.out.println("My age is "+age); }
}
    class MainClass{
public static void main(String[]arr){
// create here Person class object
Person p=new Person();
p.name="shashi";
p.age=20;
p.talk(); }
}
That is Output
e:\>javac Person.java
e:>java MainClass
hello I am shashi
My age is 20

About EasyToCode

I'm Ethan Mariano a software engineer by profession and reader/writter by passion.I have good understanding and knowledge of AngularJS, Database, javascript, web development, digital marketing and exploring other technologies related to Software development.

0 comments:

Featured post

Political Full Forms List

Acronym Full Form MLA Member of Legislative Assembly RSS Really Simple Syndication, Rashtriya Swayamsevak Sangh UNESCO United Nations E...

Powered by Blogger.